diff --git a/modules/gcp/gke/main.tf b/modules/gcp/gke/main.tf index 5dd5339..2c7af49 100644 --- a/modules/gcp/gke/main.tf +++ b/modules/gcp/gke/main.tf @@ -37,6 +37,29 @@ resource "google_compute_subnetwork" "cluster_subnet" { ] } +locals { + ng_formated_zones_list = [for ng in var.node_pools : + { + name = ng.name + machine_type = ng.machine_type + disk_size_gb = ng.disk_size_gb + disk_type = ng.disk_type + image_type = ng.image_type + autoscaling = ng.autoscaling + min_count = ng.min_count + max_count = ng.max_count + auto_repair = ng.auto_repair + auto_upgrade = ng.auto_upgrade + preemptible = ng.preemptible + enable_gcfs = ng.enable_gcfs + accelerator_type = ng.accelerator_type + accelerator_count = ng.accelerator_count + node_locations = ng.zones != null ? join(",", ng.zones) : "" + } + ] +} + + module "gke" { depends_on = [google_compute_subnetwork.cluster_subnet] source = "github.com/argonautdev/terraform-google-kubernetes-engine//modules/private-cluster?ref=v21.1.5" @@ -56,7 +79,7 @@ module "gke" { enable_vertical_pod_autoscaling = var.enable_vertical_pod_autoscaling kubernetes_version = var.kubernetes_version initial_node_count = var.initial_node_count ##How many instances should be launched in each zone - node_pools = var.node_pools + node_pools = local.ng_formated_zones_list remove_default_node_pool = var.remove_default_node_pool cluster_resource_labels = merge(var.default_labels, var.labels) //kubernetes_version = var.kubernetes_version diff --git a/modules/gcp/gke/variables.tf b/modules/gcp/gke/variables.tf index 33ccc60..35feb02 100644 --- a/modules/gcp/gke/variables.tf +++ b/modules/gcp/gke/variables.tf @@ -166,6 +166,7 @@ variable "node_pools" { enable_gcfs = bool,##Set to true only if image streaming is required. accelerator_type = optional(string), accelerator_count = optional(number), + zones = optional(list(string)) })) description = "List of maps containing node pools" default = [ @@ -177,7 +178,8 @@ variable "node_pools" { image_type = "COS_CONTAINERD" autoscaling = false auto_upgrade = false, - enable_gcfs = false + enable_gcfs = false, + zones = ["us-central1-a", "us-central1-b"] } ] }