diff --git a/example/main.tf b/example/main.tf index 68ee7bb..6d42b65 100644 --- a/example/main.tf +++ b/example/main.tf @@ -18,19 +18,19 @@ locals { } module "stackit_ske_cluster" { - source = "../ske" + for_each = var.ske_clusters + source = "../ske" + project_id = local.project_ids[each.value.project_key] + name = each.value.name + node_pools = each.value.node_pools + network = { + id = each.value.network_id + } - # required variables - project_id = local.project_ids[var.ske_target_project_key] - name = var.name - node_pools = var.node_pools - - # optional variables - kubernetes_version_min = var.kubernetes_version_min - hibernations = var.hibernations - maintenance = var.maintenance - extensions = var.extensions - network = var.network - default_region = var.default_region + kubernetes_version_min = lookup(each.value, "kubernetes_version_min", null) + hibernations = lookup(each.value, "hibernations", null) + maintenance = lookup(each.value, "maintenance", null) + extensions = lookup(each.value, "extensions", null) + default_region = var.default_region } diff --git a/example/test.tfvars b/example/test.tfvars index 93a2653..128f2eb 100644 --- a/example/test.tfvars +++ b/example/test.tfvars @@ -4,11 +4,11 @@ organization_id = "03a34540-3c1a-4794-b2c6-7111ecf824ef" Projects_map = { "projekt-alpha" = { - name = "tf_modules_test_1" + name = "tf_modules_test_3" owner_email = "janis.hahn@stackit.cloud" }, "projekt-beta" = { - name = "tf_modules_test_2" + name = "tf_modules_test_4" owner_email = "janis.hahn@stackit.cloud" } } @@ -21,63 +21,71 @@ SNA_network_ranges = [ SNA_transfer_network = "172.16.0.0/24" -name = "cluster" +ske_clusters = { -ske_target_project_key = "projekt-alpha" # projekt-alpha or projekt-beta ... or other from above to ensure scalability + "prod-cluster" = { + name = "clusterprod" + project_key = "projekt-alpha" + network_id = "53917a75-0014-49b0-a4d6-e62934ab479f" # WICHTIG: Hier die Netzwerk-ID connecten + kubernetes_version_min = "1.32.5" -node_pools = [ - { - name = "default-pool" - machine_type = "c1.2" - availability_zones = ["eu01-1"] - minimum = 1 - maximum = 2 - cri = "containerd" - volume_type = "storage_premium_perf1" - volume_size = 20 - labels = { - "worker" = "default" + node_pools = [ + { + name = "defaulpool" + machine_type = "c1.2" + availability_zones = ["eu01-1"] + minimum = 1 + maximum = 2 + cri = "containerd" + volume_type = "storage_premium_perf1" + volume_size = 21 + labels = { "worker" = "default" } + taints = [{ + effect = "NoSchedule" + key = "app" + value = "database" + }] + } + ] + + hibernations = [ + { + start = "00 18 * * 1-5" # Mo-Fr um 18:00 Uhr + end = "00 08 * * 1-5" # Mo-Fr um 08:00 Uhr + timezone = "Europe/Berlin" + } + ] + + maintenance = { + enable_kubernetes_version_updates = true + enable_machine_image_version_updates = true + start = "01:00:00Z" + end = "03:00:00Z" } - taints = [{ - effect = "NoSchedule" - key = "app" - value = "database" - }] - } -] -kubernetes_version_min = "1.32.5" + extensions = { + acl = { + enabled = true + allowed_cidrs = ["0.0.0.0/0"] + } + } + }, -hibernations = [ - { - start = "00 18 * * 1-5" # Mo-Fr um 18:00 Uhr - end = "00 08 * * 1-5" # Mo-Fr um 08:00 Uhr - timezone = "Europe/Berlin" - } - ] + "dev-cluster" = { + name = "clusterdev" + kubernetes_version_min = "1.32.5" + project_key = "projekt-beta" + network_id = "9c3dea6a-2971-414e-8c06-04618aa2c1f7" # WICHTIG: Hier die Netzwerk-ID connecten -maintenance = { - enable_kubernetes_version_updates = true - enable_machine_image_version_updates = true - start = "01:00:00Z" - end = "03:00:00Z" -} - -extensions = { - acl = { - enabled = true - allowed_cidrs = ["0.0.0.0/0"] - } - argus = { - enabled = true - argus_instance_id = "deine-argus-instanz-id" - } - dns = { - enabled = true - zones = ["example.com"] + node_pools = [ + { + name = "devpool" + machine_type = "c1.2" + availability_zones = ["eu01-2"] + minimum = 1 + maximum = 1 + volume_size = 21 + } + ] } } - -network = { - id = "bae113a7-cc47-4b1e-8abd-3cdacdd53f28" -} diff --git a/example/variables.tf b/example/variables.tf index 2e45481..f2077bb 100644 --- a/example/variables.tf +++ b/example/variables.tf @@ -4,7 +4,6 @@ variable "organization_id" { type = string } -variable "ske_target_project_key" { type = string } variable "service_account_key_path" { type = string default = "/home/hahnjan/.stackit/sa.json" @@ -41,87 +40,60 @@ variable "Projects_map" { # SKE variables -variable "name" { - description = "Ein Präfix für den Namen des SKE-Clusters." - type = string - default = "my-ske-cluster" -} +variable "ske_clusters" { + description = "Eine Map von SKE-Clustern" + type = map(object({ -variable "node_pools" { - description = "One or more node_pool blocks." - type = list(object({ - name = string - machine_type = string - availability_zones = list(string) - minimum = number - maximum = number - allow_system_components = optional(bool) - cri = optional(string) - labels = optional(map(string)) - max_surge = optional(number) - max_unavailable = optional(number) - os_name = optional(string) - os_version_min = optional(string) - taints = optional(list(object({ - effect = string - key = string - value = optional(string) + name = string + project_key = string + network_id = string + + kubernetes_version_min = optional(string) + hibernations = optional(list(object({ + start = string + end = string + timezone = optional(string) }))) - volume_size = optional(number) - volume_type = optional(string) + maintenance = optional(object({ + enable_kubernetes_version_updates = bool + enable_machine_image_version_updates = bool + start = string + end = string + })) + extensions = optional(object({ + acl = optional(object({ + enabled = bool + allowed_cidrs = list(string) + })) + argus = optional(object({ + enabled = bool + argus_instance_id = string + })) + })) + + node_pools = list(object({ + + name = string + machine_type = string + availability_zones = list(string) + minimum = number + maximum = number + + allow_system_components = optional(bool) + cri = optional(string) + labels = optional(map(string)) + max_surge = optional(number) + max_unavailable = optional(number) + os_name = optional(string) + os_version_min = optional(string) + volume_size = optional(number) + volume_type = optional(string) + taints = optional(list(object({ + effect = string + key = string + value = optional(string) + }))) + })) })) -} - -variable "kubernetes_version_min" { - description = "The minimum Kubernetes version." - type = string - default = null -} - -variable "hibernations" { - description = "A list of hibernation schedules for the cluster." - type = list(object({ - start = string - end = string - timezone = optional(string) - })) - default = null -} - -variable "maintenance" { - description = "A single maintenance block." - type = object({ - enable_kubernetes_version_updates = bool - enable_machine_image_version_updates = bool - start = string - end = string - }) - default = null -} - -variable "extensions" { - description = "A single extensions block." - type = object({ - acl = optional(object({ - enabled = bool - allowed_cidrs = list(string) - })) - argus = optional(object({ - enabled = bool - argus_instance_id = string - })) - dns = optional(object({ - enabled = bool - zones = optional(list(string)) - })) - }) - default = null -} - -variable "network" { - description = "Network block." - type = object({ - id = string - }) - default = null + default = {} } diff --git a/ske/variables.tf b/ske/variables.tf index 2f70fc6..ccae10c 100644 --- a/ske/variables.tf +++ b/ske/variables.tf @@ -33,7 +33,7 @@ variable "node_pools" { })) } -# -- Optionale Variablen -- +# Optionale Variablen variable "kubernetes_version_min" { description = "The minimum Kubernetes version." type = string