@@ -36,8 +36,9 @@ resource "google_container_cluster" "primary" {
3636 cluster_ipv4_cidr = var.cluster_ipv4_cidr
3737 network = "projects/${local.network_project_id}/global/networks/${var.network}"
3838 deletion_protection = var.deletion_protection
39-
4039 {% if autopilot_cluster != true %}
40+ initial_node_count = length(var.node_pools) == 0 ? var.initial_node_count : null
41+
4142 dynamic "network_policy" {
4243 for_each = local.cluster_network_policy
4344
@@ -579,121 +580,124 @@ resource "google_container_cluster" "primary" {
579580 delete = lookup(var.timeouts, "delete", "45m")
580581 }
581582 {% if autopilot_cluster != true %}
582- node_pool {
583- name = "default-pool"
584- initial_node_count = var.initial_node_count
585-
586- management {
587- auto_repair = lookup(var.cluster_autoscaling, "auto_repair", true)
588- auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", true)
589- }
590-
591- node_config {
592- image_type = lookup(var.node_pools[0], "image_type", "COS_CONTAINERD")
593- machine_type = lookup(var.node_pools[0], "machine_type", "e2-medium")
594- min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "")
595- enable_confidential_storage = lookup(var.node_pools[0], "enable_confidential_storage", false)
596- disk_type = lookup(var.node_pools[0], "disk_type", null)
597- dynamic "gcfs_config" {
598- for_each = lookup(var.node_pools[0], "enable_gcfs", null) != null ? [var.node_pools[0].enable_gcfs] : []
599- content {
600- enabled = gcfs_config.value
601- }
583+ dynamic "node_pool" {
584+ for_each = length(var.node_pools) == 0 ? [] : [1]
585+ content {
586+ name = "default-pool"
587+ initial_node_count = var.initial_node_count
588+
589+ management {
590+ auto_repair = lookup(var.cluster_autoscaling, "auto_repair", true)
591+ auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", true)
602592 }
603593
604- dynamic "gvnic" {
605- for_each = lookup(var.node_pools[0], "enable_gvnic", false) ? [true] : []
606- content {
607- enabled = gvnic.value
594+ node_config {
595+ image_type = lookup(var.node_pools[0], "image_type", "COS_CONTAINERD")
596+ machine_type = lookup(var.node_pools[0], "machine_type", "e2-medium")
597+ min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "")
598+ enable_confidential_storage = lookup(var.node_pools[0], "enable_confidential_storage", false)
599+ disk_type = lookup(var.node_pools[0], "disk_type", null)
600+ dynamic "gcfs_config" {
601+ for_each = lookup(var.node_pools[0], "enable_gcfs", null) != null ? [var.node_pools[0].enable_gcfs] : []
602+ content {
603+ enabled = gcfs_config.value
604+ }
608605 }
609- }
610606
611- dynamic "fast_socket" {
612- for_each = lookup(var.node_pools[0], "enable_fast_socket", null) != null ? [var.node_pools[0].enable_fast_socket] : []
613- content {
614- enabled = fast_socket.value
607+ dynamic "gvnic" {
608+ for_each = lookup(var.node_pools[0], "enable_gvnic", false) ? [true] : []
609+ content {
610+ enabled = gvnic.value
611+ }
615612 }
616- }
617613
618- dynamic "kubelet_config" {
619- for_each = length(setintersection(
620- keys(var.node_pools[0]),
621- ["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period", "insecure_kubelet_readonly_port_enabled", "pod_pids_limit", "container_log_max_size", "container_log_max_files", "image_gc_low_threshold_percent", "image_gc_high_threshold_percent", "image_minimum_gc_age", "image_maximum_gc_age", "allowed_unsafe_sysctls"]
622- )) != 0 || var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
614+ dynamic "fast_socket" {
615+ for_each = lookup(var.node_pools[0], "enable_fast_socket", null) != null ? [var.node_pools[0].enable_fast_socket] : []
616+ content {
617+ enabled = fast_socket.value
618+ }
619+ }
623620
624- content {
625- cpu_manager_policy = lookup(var.node_pools[0], "cpu_manager_policy", "static")
626- cpu_cfs_quota = lookup(var.node_pools[0], "cpu_cfs_quota", null)
627- cpu_cfs_quota_period = lookup(var.node_pools[0], "cpu_cfs_quota_period", null)
628- insecure_kubelet_readonly_port_enabled = lookup(var.node_pools[0], "insecure_kubelet_readonly_port_enabled", var.insecure_kubelet_readonly_port_enabled) != null ? upper(tostring(lookup(var.node_pools[0], "insecure_kubelet_readonly_port_enabled", var.insecure_kubelet_readonly_port_enabled))) : null
629- pod_pids_limit = lookup(var.node_pools[0], "pod_pids_limit", null)
630- container_log_max_size = lookup(var.node_pools[0], "container_log_max_size", null)
631- container_log_max_files = lookup(var.node_pools[0], "container_log_max_files", null)
632- image_gc_low_threshold_percent = lookup(var.node_pools[0], "image_gc_low_threshold_percent", null)
633- image_gc_high_threshold_percent = lookup(var.node_pools[0], "image_gc_high_threshold_percent", null)
634- image_minimum_gc_age = lookup(var.node_pools[0], "image_minimum_gc_age", null)
635- image_maximum_gc_age = lookup(var.node_pools[0], "image_maximum_gc_age", null)
636- allowed_unsafe_sysctls = lookup(var.node_pools[0], "allowed_unsafe_sysctls", null) == null ? null : [for s in split(",", lookup(var.node_pools[0], "allowed_unsafe_sysctls", null)) : trimspace(s)]
621+ dynamic "kubelet_config" {
622+ for_each = length(setintersection(
623+ keys(var.node_pools[0]),
624+ ["cpu_manager_policy", "cpu_cfs_quota", "cpu_cfs_quota_period", "insecure_kubelet_readonly_port_enabled", "pod_pids_limit", "container_log_max_size", "container_log_max_files", "image_gc_low_threshold_percent", "image_gc_high_threshold_percent", "image_minimum_gc_age", "image_maximum_gc_age", "allowed_unsafe_sysctls"]
625+ )) != 0 || var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
626+
627+ content {
628+ cpu_manager_policy = lookup(var.node_pools[0], "cpu_manager_policy", "static")
629+ cpu_cfs_quota = lookup(var.node_pools[0], "cpu_cfs_quota", null)
630+ cpu_cfs_quota_period = lookup(var.node_pools[0], "cpu_cfs_quota_period", null)
631+ insecure_kubelet_readonly_port_enabled = lookup(var.node_pools[0], "insecure_kubelet_readonly_port_enabled", var.insecure_kubelet_readonly_port_enabled) != null ? upper(tostring(lookup(var.node_pools[0], "insecure_kubelet_readonly_port_enabled", var.insecure_kubelet_readonly_port_enabled))) : null
632+ pod_pids_limit = lookup(var.node_pools[0], "pod_pids_limit", null)
633+ container_log_max_size = lookup(var.node_pools[0], "container_log_max_size", null)
634+ container_log_max_files = lookup(var.node_pools[0], "container_log_max_files", null)
635+ image_gc_low_threshold_percent = lookup(var.node_pools[0], "image_gc_low_threshold_percent", null)
636+ image_gc_high_threshold_percent = lookup(var.node_pools[0], "image_gc_high_threshold_percent", null)
637+ image_minimum_gc_age = lookup(var.node_pools[0], "image_minimum_gc_age", null)
638+ image_maximum_gc_age = lookup(var.node_pools[0], "image_maximum_gc_age", null)
639+ allowed_unsafe_sysctls = lookup(var.node_pools[0], "allowed_unsafe_sysctls", null) == null ? null : [for s in split(",", lookup(var.node_pools[0], "allowed_unsafe_sysctls", null)) : trimspace(s)]
640+ }
637641 }
638- }
639642
640- dynamic "sole_tenant_config" {
641- # node_affinity is currently the only member of sole_tenant_config
642- for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [true] : []
643- content {
644- dynamic "node_affinity" {
645- for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [lookup(var.node_pools[0], "node_affinity", null)] : []
646- content {
647- key = lookup(jsondecode(node_affinity.value), "key", null)
648- operator = lookup(jsondecode(node_affinity.value), "operator", null)
649- values = lookup(jsondecode(node_affinity.value), "values", [])
643+ dynamic "sole_tenant_config" {
644+ # node_affinity is currently the only member of sole_tenant_config
645+ for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [true] : []
646+ content {
647+ dynamic "node_affinity" {
648+ for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [lookup(var.node_pools[0], "node_affinity", null)] : []
649+ content {
650+ key = lookup(jsondecode(node_affinity.value), "key", null)
651+ operator = lookup(jsondecode(node_affinity.value), "operator", null)
652+ values = lookup(jsondecode(node_affinity.value), "values", [])
653+ }
650654 }
651655 }
652656 }
653- }
654657
655- service_account = lookup(var.node_pools[0], "service_account", local.service_account)
658+ service_account = lookup(var.node_pools[0], "service_account", local.service_account)
656659
657- tags = concat(
658- lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
659- lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
660- lookup(local.node_pools_tags, "all", []),
661- lookup(local.node_pools_tags, var.node_pools[0].name, []),
662- )
660+ tags = concat(
661+ lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
662+ lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
663+ lookup(local.node_pools_tags, "all", []),
664+ lookup(local.node_pools_tags, var.node_pools[0].name, []),
665+ )
663666
664- logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
667+ logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
665668
666- dynamic "workload_metadata_config" {
667- for_each = local.cluster_node_metadata_config
669+ dynamic "workload_metadata_config" {
670+ for_each = local.cluster_node_metadata_config
668671
669- content {
670- mode = workload_metadata_config.value.mode
672+ content {
673+ mode = workload_metadata_config.value.mode
674+ }
671675 }
672- }
673676
674- metadata = local.node_pools_metadata["all"]
677+ metadata = local.node_pools_metadata["all"]
675678
676- {% if beta_cluster %}
677- dynamic "sandbox_config" {
678- for_each = tobool((lookup(var.node_pools[0], "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
679- content {
680- sandbox_type = sandbox_config.value
679+ {% if beta_cluster %}
680+ dynamic "sandbox_config" {
681+ for_each = tobool((lookup(var.node_pools[0], "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
682+ content {
683+ sandbox_type = sandbox_config.value
684+ }
681685 }
682- }
683686
684- {% endif %}
685- boot_disk_kms_key = lookup(var.node_pools[0], "boot_disk_kms_key", var.boot_disk_kms_key)
687+ {% endif %}
688+ boot_disk_kms_key = lookup(var.node_pools[0], "boot_disk_kms_key", var.boot_disk_kms_key)
686689
687- storage_pools = lookup(var.node_pools[0], "storage_pools", null) != null ? [var.node_pools[0].storage_pools] : []
690+ storage_pools = lookup(var.node_pools[0], "storage_pools", null) != null ? [var.node_pools[0].storage_pools] : []
688691
689- shielded_instance_config {
690- enable_secure_boot = lookup(var.node_pools[0], "enable_secure_boot", false)
691- enable_integrity_monitoring = lookup(var.node_pools[0], "enable_integrity_monitoring", true)
692- }
692+ shielded_instance_config {
693+ enable_secure_boot = lookup(var.node_pools[0], "enable_secure_boot", false)
694+ enable_integrity_monitoring = lookup(var.node_pools[0], "enable_integrity_monitoring", true)
695+ }
693696
694- local_ssd_encryption_mode = lookup(var.node_pools[0], "local_ssd_encryption_mode", null)
695- max_run_duration = lookup(var.node_pools[0], "max_run_duration", null)
696- flex_start = lookup(var.node_pools[0], "flex_start", null)
697+ local_ssd_encryption_mode = lookup(var.node_pools[0], "local_ssd_encryption_mode", null)
698+ max_run_duration = lookup(var.node_pools[0], "max_run_duration", null)
699+ flex_start = lookup(var.node_pools[0], "flex_start", null)
700+ }
697701 }
698702 }
699703 {% endif %}
0 commit comments