@@ -36,8 +36,9 @@ resource "google_container_cluster" "primary" {
36
36
cluster_ipv4_cidr = var.cluster_ipv4_cidr
37
37
network = "projects/${local.network_project_id}/global/networks/${var.network}"
38
38
deletion_protection = var.deletion_protection
39
-
40
39
{% if autopilot_cluster != true %}
40
+ initial_node_count = length(var.node_pools) == 0 ? var.initial_node_count : null
41
+
41
42
dynamic "network_policy" {
42
43
for_each = local.cluster_network_policy
43
44
@@ -579,121 +580,124 @@ resource "google_container_cluster" "primary" {
579
580
delete = lookup(var.timeouts, "delete", "45m")
580
581
}
581
582
{% 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)
602
592
}
603
593
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
+ }
608
605
}
609
- }
610
606
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
+ }
615
612
}
616
- }
617
613
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
+ }
623
620
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
+ }
637
641
}
638
- }
639
642
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
+ }
650
654
}
651
655
}
652
656
}
653
- }
654
657
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)
656
659
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
+ )
663
666
664
- logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
667
+ logging_variant = lookup(var.node_pools[0], "logging_variant", "DEFAULT")
665
668
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
668
671
669
- content {
670
- mode = workload_metadata_config.value.mode
672
+ content {
673
+ mode = workload_metadata_config.value.mode
674
+ }
671
675
}
672
- }
673
676
674
- metadata = local.node_pools_metadata["all"]
677
+ metadata = local.node_pools_metadata["all"]
675
678
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
+ }
681
685
}
682
- }
683
686
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)
686
689
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] : []
688
691
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
+ }
693
696
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
+ }
697
701
}
698
702
}
699
703
{% endif %}
0 commit comments