Simplify server and agent definition for kubernetes

The definition was split into multiple settings, that made it
unnecessary complicated to setup the definition for my kubernetes
cluster. This new approach allows for granular definitions of servers
and agents and is also simpler to use for me.
This commit is contained in:
2025-10-17 13:02:59 +02:00
parent 58b0c0fcc7
commit b33da3eca0
2 changed files with 20 additions and 41 deletions

12
main.tf
View File

@@ -9,16 +9,8 @@ module "k8s" {
name = "cluster1" name = "cluster1"
ssh_keys = [for o in hcloud_ssh_key.this : o.id] ssh_keys = [for o in hcloud_ssh_key.this : o.id]
servers = [for n in range(var.k8s_server_count) : { servers = var.k8s_servers
type = var.k8s_server_type agents = var.k8s_agents
location = var.k8s_location
ip_datacenter = var.k8s_ip_datacenter
}]
agents = [{
type = var.k8s_agent_type
location = var.k8s_location
count = var.k8s_agent_count
}]
auto_delete_primary_ips = false auto_delete_primary_ips = false
kubernetes_exposed_ips = var.kubernetes_allowed_ips kubernetes_exposed_ips = var.kubernetes_allowed_ips
ssh_exposed_ips = var.ssh_allowed_ips ssh_exposed_ips = var.ssh_allowed_ips

View File

@@ -20,45 +20,32 @@ variable "ssh_keys" {
type = map(string) type = map(string)
} }
# Right now this only supports 1 location, but that's okay for me! variable "k8s_servers" {
variable "k8s_location" { type = list(object({
type = string type = optional(string, "cax11")
location = string
ip_datacenter = string
}))
description = <<EOF description = <<EOF
This is the location where I host the k8s-cluster. The servers of the kubernetes-cluster.
An overview of possible locations can be found at: https://docs.hetzner.com/cloud/general/locations/ This should always contain an off number of servers.
An overview of locations can be found at: https://docs.hetzner.com/cloud/general/locations/
Note, that the ip_datacenter has to match the location.
EOF EOF
} }
variable "k8s_ip_datacenter" { variable "k8s_agents" {
type = string type = list(object({
type = optional(string, "cax11")
location = string
count = optional(number, 1)
}))
description = <<EOF description = <<EOF
This is the datacenter where the public IPs of the k8s-cluster belong to. The agents of the kubernetes-cluster.
An overview of possible locations can be found at: https://docs.hetzner.com/cloud/general/locations/ An overview of locations can be found at: https://docs.hetzner.com/cloud/general/locations/
Note, that the k8s_ip_datacenter has to match the k8s_location!
EOF EOF
} }
variable "k8s_server_count" {
type = number
default = 3
description = "Number of k8s-server nodes. This should always be an odd number."
}
variable "k8s_server_type" {
type = string
default = "cax11"
}
variable "k8s_agent_count" {
type = number
default = 3
}
variable "k8s_agent_type" {
type = string
default = "cax11"
}
variable "dns_zones" { variable "dns_zones" {
type = map(object({ type = map(object({
zone_ttl = optional(number, 900) zone_ttl = optional(number, 900)