@@ -45,6 +45,8 @@ resource "google_container_cluster" "primary" {
4545 }
4646
4747 {% if autopilot_cluster != true %}
48+ initial_node_count = length(var.node_pools) == 0 ? var.initial_node_count : null
49+
4850 dynamic "network_policy" {
4951 for_each = local.cluster_network_policy
5052
@@ -604,121 +606,124 @@ resource "google_container_cluster" "primary" {
604606 delete = lookup(var.timeouts, "delete", "45m")
605607 }
606608 {% if autopilot_cluster != true %}
607- node_pool {
608- name = "default-pool"
609- initial_node_count = var.initial_node_count
610-
611- management {
612- auto_repair = lookup(var.cluster_autoscaling, "auto_repair", true)
613- auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", true)
614- }
615-
616- node_config {
617- image_type = lookup(var.node_pools[0], "image_type", "COS_CONTAINERD")
618- machine_type = lookup(var.node_pools[0], "machine_type", "e2-medium")
619- min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "")
620- enable_confidential_storage = lookup(var.node_pools[0], "enable_confidential_storage", false)
621- disk_type = lookup(var.node_pools[0], "disk_type", null)
622- dynamic "gcfs_config" {
623- for_each = lookup(var.node_pools[0], "enable_gcfs", null) != null ? [var.node_pools[0].enable_gcfs] : []
624- content {
625- enabled = gcfs_config.value
626- }
609+ dynamic "node_pool" {
610+ for_each = length(var.node_pools) == 0 ? [] : [1]
611+ content {
612+ name = "default-pool"
613+ initial_node_count = var.initial_node_count
614+
615+ management {
616+ auto_repair = lookup(var.cluster_autoscaling, "auto_repair", true)
617+ auto_upgrade = lookup(var.cluster_autoscaling, "auto_upgrade", true)
627618 }
628619
629- dynamic "gvnic" {
630- for_each = lookup(var.node_pools[0], "enable_gvnic", false) ? [true] : []
631- content {
632- enabled = gvnic.value
620+ node_config {
621+ image_type = lookup(var.node_pools[0], "image_type", "COS_CONTAINERD")
622+ machine_type = lookup(var.node_pools[0], "machine_type", "e2-medium")
623+ min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "")
624+ enable_confidential_storage = lookup(var.node_pools[0], "enable_confidential_storage", false)
625+ disk_type = lookup(var.node_pools[0], "disk_type", null)
626+ dynamic "gcfs_config" {
627+ for_each = lookup(var.node_pools[0], "enable_gcfs", null) != null ? [var.node_pools[0].enable_gcfs] : []
628+ content {
629+ enabled = gcfs_config.value
630+ }
633631 }
634- }
635632
636- dynamic "fast_socket" {
637- for_each = lookup(var.node_pools[0], "enable_fast_socket", null) != null ? [var.node_pools[0].enable_fast_socket] : []
638- content {
639- enabled = fast_socket.value
633+ dynamic "gvnic" {
634+ for_each = lookup(var.node_pools[0], "enable_gvnic", false) ? [true] : []
635+ content {
636+ enabled = gvnic.value
637+ }
640638 }
641- }
642639
643- dynamic "kubelet_config" {
644- for_each = length(setintersection(
645- keys(var.node_pools[0]),
646- ["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"]
647- )) != 0 || var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
640+ dynamic "fast_socket" {
641+ for_each = lookup(var.node_pools[0], "enable_fast_socket", null) != null ? [var.node_pools[0].enable_fast_socket] : []
642+ content {
643+ enabled = fast_socket.value
644+ }
645+ }
648646
649- content {
650- cpu_manager_policy = lookup(var.node_pools[0], "cpu_manager_policy", "static")
651- cpu_cfs_quota = lookup(var.node_pools[0], "cpu_cfs_quota", null)
652- cpu_cfs_quota_period = lookup(var.node_pools[0], "cpu_cfs_quota_period", null)
653- 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
654- pod_pids_limit = lookup(var.node_pools[0], "pod_pids_limit", null)
655- container_log_max_size = lookup(var.node_pools[0], "container_log_max_size", null)
656- container_log_max_files = lookup(var.node_pools[0], "container_log_max_files", null)
657- image_gc_low_threshold_percent = lookup(var.node_pools[0], "image_gc_low_threshold_percent", null)
658- image_gc_high_threshold_percent = lookup(var.node_pools[0], "image_gc_high_threshold_percent", null)
659- image_minimum_gc_age = lookup(var.node_pools[0], "image_minimum_gc_age", null)
660- image_maximum_gc_age = lookup(var.node_pools[0], "image_maximum_gc_age", null)
661- 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)]
647+ dynamic "kubelet_config" {
648+ for_each = length(setintersection(
649+ keys(var.node_pools[0]),
650+ ["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"]
651+ )) != 0 || var.insecure_kubelet_readonly_port_enabled != null ? [1] : []
652+
653+ content {
654+ cpu_manager_policy = lookup(var.node_pools[0], "cpu_manager_policy", "static")
655+ cpu_cfs_quota = lookup(var.node_pools[0], "cpu_cfs_quota", null)
656+ cpu_cfs_quota_period = lookup(var.node_pools[0], "cpu_cfs_quota_period", null)
657+ 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
658+ pod_pids_limit = lookup(var.node_pools[0], "pod_pids_limit", null)
659+ container_log_max_size = lookup(var.node_pools[0], "container_log_max_size", null)
660+ container_log_max_files = lookup(var.node_pools[0], "container_log_max_files", null)
661+ image_gc_low_threshold_percent = lookup(var.node_pools[0], "image_gc_low_threshold_percent", null)
662+ image_gc_high_threshold_percent = lookup(var.node_pools[0], "image_gc_high_threshold_percent", null)
663+ image_minimum_gc_age = lookup(var.node_pools[0], "image_minimum_gc_age", null)
664+ image_maximum_gc_age = lookup(var.node_pools[0], "image_maximum_gc_age", null)
665+ 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)]
666+ }
662667 }
663- }
664668
665- dynamic "sole_tenant_config" {
666- # node_affinity is currently the only member of sole_tenant_config
667- for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [true] : []
668- content {
669- dynamic "node_affinity" {
670- for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [lookup(var.node_pools[0], "node_affinity", null)] : []
671- content {
672- key = lookup(jsondecode(node_affinity.value), "key", null)
673- operator = lookup(jsondecode(node_affinity.value), "operator", null)
674- values = lookup(jsondecode(node_affinity.value), "values", [])
669+ dynamic "sole_tenant_config" {
670+ # node_affinity is currently the only member of sole_tenant_config
671+ for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [true] : []
672+ content {
673+ dynamic "node_affinity" {
674+ for_each = lookup(var.node_pools[0], "node_affinity", null) != null ? [lookup(var.node_pools[0], "node_affinity", null)] : []
675+ content {
676+ key = lookup(jsondecode(node_affinity.value), "key", null)
677+ operator = lookup(jsondecode(node_affinity.value), "operator", null)
678+ values = lookup(jsondecode(node_affinity.value), "values", [])
679+ }
675680 }
676681 }
677682 }
678- }
679683
680- service_account = lookup(var.node_pools[0], "service_account", local.service_account)
684+ service_account = lookup(var.node_pools[0], "service_account", local.service_account)
681685
682- tags = concat(
683- lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
684- lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
685- lookup(local.node_pools_tags, "all", []),
686- lookup(local.node_pools_tags, var.node_pools[0].name, []),
687- )
686+ tags = concat(
687+ lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
688+ lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
689+ lookup(local.node_pools_tags, "all", []),
690+ lookup(local.node_pools_tags, var.node_pools[0].name, []),
691+ )
688692
689- logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
693+ logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
690694
691- dynamic "workload_metadata_config" {
692- for_each = local.cluster_node_metadata_config
695+ dynamic "workload_metadata_config" {
696+ for_each = local.cluster_node_metadata_config
693697
694- content {
695- mode = workload_metadata_config.value.mode
698+ content {
699+ mode = workload_metadata_config.value.mode
700+ }
696701 }
697- }
698702
699- metadata = local.node_pools_metadata["all"]
703+ metadata = local.node_pools_metadata["all"]
700704
701- {% if beta_cluster %}
702- dynamic "sandbox_config" {
703- for_each = tobool((lookup(var.node_pools[0], "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
704- content {
705- sandbox_type = sandbox_config.value
705+ {% if beta_cluster %}
706+ dynamic "sandbox_config" {
707+ for_each = tobool((lookup(var.node_pools[0], "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
708+ content {
709+ sandbox_type = sandbox_config.value
710+ }
706711 }
707- }
708712
709- {% endif %}
710- boot_disk_kms_key = lookup(var.node_pools[0], "boot_disk_kms_key", var.boot_disk_kms_key)
713+ {% endif %}
714+ boot_disk_kms_key = lookup(var.node_pools[0], "boot_disk_kms_key", var.boot_disk_kms_key)
711715
712- storage_pools = lookup(var.node_pools[0], "storage_pools", null) != null ? [var.node_pools[0].storage_pools] : []
716+ storage_pools = lookup(var.node_pools[0], "storage_pools", null) != null ? [var.node_pools[0].storage_pools] : []
713717
714- shielded_instance_config {
715- enable_secure_boot = lookup(var.node_pools[0], "enable_secure_boot", false)
716- enable_integrity_monitoring = lookup(var.node_pools[0], "enable_integrity_monitoring", true)
717- }
718+ shielded_instance_config {
719+ enable_secure_boot = lookup(var.node_pools[0], "enable_secure_boot", false)
720+ enable_integrity_monitoring = lookup(var.node_pools[0], "enable_integrity_monitoring", true)
721+ }
718722
719- local_ssd_encryption_mode = lookup(var.node_pools[0], "local_ssd_encryption_mode", null)
720- max_run_duration = lookup(var.node_pools[0], "max_run_duration", null)
721- flex_start = lookup(var.node_pools[0], "flex_start", null)
723+ local_ssd_encryption_mode = lookup(var.node_pools[0], "local_ssd_encryption_mode", null)
724+ max_run_duration = lookup(var.node_pools[0], "max_run_duration", null)
725+ flex_start = lookup(var.node_pools[0], "flex_start", null)
726+ }
722727 }
723728 }
724729 {% endif %}
0 commit comments