infrastructure/k8s.tjo.cloud/main.tf

116 lines
2.5 KiB
Terraform
Raw Normal View History

2024-08-02 20:10:21 +00:00
locals {
cluster_domain = "k8s.tjo.cloud"
}
resource "tailscale_tailnet_key" "nodes" {
reusable = true
ephemeral = true
preauthorized = true
tags = ["tag:kubernetes-tjo-cloud"]
description = "tailscale key for k8s-tjo-cloud nodes"
}
module "cluster" {
2024-07-27 14:08:21 +00:00
source = "./modules/cluster"
providers = {
helm.template = helm.template
}
talos = {
version = "v1.7.5"
kubernetes = "v1.30.0"
}
cluster = {
2024-08-02 20:10:21 +00:00
name = "k8s-tjo-cloud"
oidc = {
client_id = var.oidc_client_id
issuer_url = var.oidc_issuer_url
}
}
proxmox = {
name = "tjo-cloud"
url = "https://proxmox.tjo.cloud/api2/json"
2024-07-19 20:48:07 +00:00
common_storage = "proxmox-backup-tjo-cloud"
}
2024-08-02 20:10:21 +00:00
tailscale_authkey = tailscale_tailnet_key.nodes.key
nodes = {
pink = {
2024-08-02 20:10:21 +00:00
public = false
2024-07-19 20:48:07 +00:00
type = "controlplane"
host = "hetzner"
2024-07-21 10:27:40 +00:00
storage = "main"
2024-07-19 20:48:07 +00:00
cores = 4
memory = 4096
}
blue = {
2024-07-19 20:48:07 +00:00
public = false
type = "worker"
host = "hetzner"
2024-07-21 10:27:40 +00:00
storage = "main"
cores = 6
2024-07-19 20:48:07 +00:00
memory = 16384
}
cyan = {
2024-07-19 20:48:07 +00:00
public = false
type = "worker"
host = "hetzner"
2024-07-21 10:27:40 +00:00
storage = "main"
cores = 6
2024-07-19 20:48:07 +00:00
memory = 16384
}
}
}
2024-08-02 20:10:21 +00:00
data "tailscale_device" "controlpane" {
for_each = { for k, v in module.cluster.nodes : k => v if v.type == "controlplane" }
hostname = each.value.name
}
2024-08-04 17:50:50 +00:00
resource "digitalocean_record" "api-internal" {
2024-08-02 20:10:21 +00:00
for_each = toset(flatten([for key, device in data.tailscale_device.controlpane : device.addresses]))
domain = local.cluster_domain
type = strcontains(each.value, ":") ? "AAAA" : "A"
2024-08-04 17:50:50 +00:00
name = trimsuffix(module.cluster.api.internal.domain, ".${local.cluster_domain}")
2024-08-02 20:10:21 +00:00
value = each.value
ttl = 30
}
resource "local_file" "kubeconfig" {
2024-08-04 17:50:50 +00:00
content = templatefile("${path.module}/kubeconfig.tftpl", {
cluster : {
name : module.cluster.name,
endpoint : module.cluster.api.public.endpoint,
ca : module.cluster.api.ca,
}
oidc : {
issuer : var.oidc_issuer_url,
id : var.oidc_client_id,
}
})
filename = "${path.module}/kubeconfig"
}
2024-07-23 18:42:22 +00:00
module "cluster-core" {
2024-07-27 14:08:21 +00:00
source = "./modules/cluster-core"
cluster_name = module.cluster.name
2024-07-23 18:42:22 +00:00
}
module "cluster-components" {
2024-07-27 14:08:21 +00:00
source = "./modules/cluster-components"
2024-07-20 11:09:30 +00:00
oidc_issuer_url = var.oidc_issuer_url
oidc_client_id = var.oidc_client_id
digitalocean_token = var.digitalocean_token
cluster_name = module.cluster.name
2024-08-02 20:10:21 +00:00
cluster_domain = "k8s.tjo.cloud"
}