From 3bcf9cc2b6897249066e3ac4fa29188014eb1f31 Mon Sep 17 00:00:00 2001 From: Janis Hahn Date: Sat, 12 Jul 2025 11:13:36 +0200 Subject: [PATCH] add: add: optional variables in ske --- example/main.tf | 29 ++++++++++++ example/providers.tf | 16 +++++++ example/test.tfvars | 57 +++++++++++++++++++++++ example/variables.tf | 106 +++++++++++++++++++++++++++++++++++++++++++ main.tf | 8 ++-- ske/main.tf | 14 ++++-- ske/variables.tf | 103 ++++++++++++++++++++++++++++++++++++----- 7 files changed, 314 insertions(+), 19 deletions(-) create mode 100644 example/main.tf create mode 100644 example/providers.tf create mode 100644 example/test.tfvars create mode 100644 example/variables.tf diff --git a/example/main.tf b/example/main.tf new file mode 100644 index 0000000..1316f62 --- /dev/null +++ b/example/main.tf @@ -0,0 +1,29 @@ +module "stackit_ske_cluster" { + source = "../ske" # Pfad zu deinem Modul-Ordner + + # Erforderliche Variablen + project_id = var.project_id + name = var.name + node_pools = var.node_pools + + # Optionale Variablen + kubernetes_version_min = var.kubernetes_version_min + allow_privileged_containers = var.allow_privileged_containers + hibernations = var.hibernations + maintenance = var.maintenance + extensions = var.extensions + network = var.network + default_region = var.default_region +} + +/* +module "stackit_ske_cluster" { + source = "../ske" + + project_id = var.project_id + name = var.name + kubernetes_version_min = var.kubernetes_version_min + node_pools = var.node_pools + hibernations = var.hibernations +} +*/ \ No newline at end of file diff --git a/example/providers.tf b/example/providers.tf new file mode 100644 index 0000000..ba2ffb3 --- /dev/null +++ b/example/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_version = ">= 1.9.0" + required_providers { + stackit = { + source = "stackitcloud/stackit" + version = "0.56.0" + } + } +} + +provider "stackit" { + default_region = var.default_region + service_account_key_path = var.service_account_key_path + enable_beta_resources = true +} + diff --git a/example/test.tfvars b/example/test.tfvars new file mode 100644 index 0000000..da28541 --- /dev/null +++ b/example/test.tfvars @@ -0,0 +1,57 @@ + + +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" + } + taints = [{ + effect = "NoSchedule" + key = "app" + value = "database" + }] + } +] + +kubernetes_version_min = "1.29" + +allow_privileged_containers = false + +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" +} + +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"] + } +} + diff --git a/example/variables.tf b/example/variables.tf new file mode 100644 index 0000000..65fc872 --- /dev/null +++ b/example/variables.tf @@ -0,0 +1,106 @@ +variable "project_id" { + description = "STACKIT Cloud project ID" + type = string + default = "6f9528aa-27c8-4e97-a0f7-51bbf3be417c" +} + +variable "service_account_key_path" { + type = string + default = "/home/hahnjan/.stackit/sa.json" +} + +variable "default_region" { + type = string + default = "eu01" +} + +variable "name" { + description = "Ein Präfix für den Namen des SKE-Clusters." + type = string + default = "my-ske-cluster" +} + +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) + }))) + volume_size = optional(number) + volume_type = optional(string) + })) +} + +variable "kubernetes_version_min" { + description = "The minimum Kubernetes version." + type = string + default = null +} + +variable "allow_privileged_containers" { + description = "Flag to specify if privileged mode for containers is enabled or not." + type = bool + 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 +} diff --git a/main.tf b/main.tf index c702464..ecb00bb 100644 --- a/main.tf +++ b/main.tf @@ -10,7 +10,7 @@ terraform { } provider "stackit" { - default_region = var.default_region + default_region = var.default_region service_account_key_path = var.service_account_key_path private_key_path = var.private_key_path enable_beta_resources = true @@ -21,10 +21,12 @@ module "project" { source = "./project" # -- variables for project module - organization_id = var.organization_id - sna_net = var.sna_net + organization_id = var.organization_id + sna_net = var.sna_net } + + diff --git a/ske/main.tf b/ske/main.tf index 90124a0..db7d8ed 100644 --- a/ske/main.tf +++ b/ske/main.tf @@ -1,8 +1,14 @@ resource "stackit_ske_cluster" "this" { - project_id = var.project_id - name = var.name - kubernetes_version_min = var.kubernetes_version_min - node_pools = var.node_pools + project_id = var.project_id + name = var.name + node_pools = var.node_pools + kubernetes_version_min = var.kubernetes_version_min + allow_privileged_containers = var.allow_privileged_containers + hibernations = var.hibernations + maintenance = var.maintenance + extensions = var.extensions + network = var.network + region = var.default_region } resource "stackit_ske_kubeconfig" "admin" { diff --git a/ske/variables.tf b/ske/variables.tf index 53533c0..dd9aa96 100644 --- a/ske/variables.tf +++ b/ske/variables.tf @@ -1,22 +1,101 @@ variable "project_id" { - type = string + description = "STACKIT project ID to which the cluster is associated." + type = string } variable "name" { - type = string -} - -variable "kubernetes_version_min" { - type = string + description = "The cluster name." + type = string } variable "node_pools" { + description = "One or more node_pool blocks." type = list(object({ - name = string - machine_type = string - availability_zones = list(string) - volume_size = number - minimum = number - maximum = number + 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) + }))) + volume_size = optional(number) + volume_type = optional(string) })) } + +# -- Optionale Variablen -- +variable "kubernetes_version_min" { + description = "The minimum Kubernetes version." + type = string + default = null +} + +variable "allow_privileged_containers" { + description = "Flag to specify if privileged mode for containers is enabled or not." + type = bool + 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 +} + +variable "default_region" { + description = "The resource region." + type = string + default = null +} \ No newline at end of file