@@ -32,6 +32,7 @@ resource "google_container_cluster" "primary" {
32
32
cluster_ipv4_cidr = var. cluster_ipv4_cidr
33
33
network = " projects/${ local . network_project_id } /global/networks/${ var . network } "
34
34
deletion_protection = var. deletion_protection
35
+ initial_node_count = length (var. node_pools ) == 0 ? var. initial_node_count : null
35
36
36
37
dynamic "network_policy" {
37
38
for_each = local. cluster_network_policy
@@ -439,112 +440,115 @@ resource "google_container_cluster" "primary" {
439
440
update = lookup (var. timeouts , " update" , " 45m" )
440
441
delete = lookup (var. timeouts , " delete" , " 45m" )
441
442
}
442
- node_pool {
443
- name = " default-pool"
444
- initial_node_count = var. initial_node_count
445
-
446
- management {
447
- auto_repair = lookup (var. cluster_autoscaling , " auto_repair" , true )
448
- auto_upgrade = lookup (var. cluster_autoscaling , " auto_upgrade" , true )
449
- }
450
-
451
- node_config {
452
- image_type = lookup (var. node_pools [0 ], " image_type" , " COS_CONTAINERD" )
453
- machine_type = lookup (var. node_pools [0 ], " machine_type" , " e2-medium" )
454
- min_cpu_platform = lookup (var. node_pools [0 ], " min_cpu_platform" , " " )
455
- enable_confidential_storage = lookup (var. node_pools [0 ], " enable_confidential_storage" , false )
456
- disk_type = lookup (var. node_pools [0 ], " disk_type" , null )
457
- dynamic "gcfs_config" {
458
- for_each = lookup (var. node_pools [0 ], " enable_gcfs" , null ) != null ? [var . node_pools [0 ]. enable_gcfs ] : []
459
- content {
460
- enabled = gcfs_config. value
443
+ dynamic "node_pool" {
444
+ for_each = length (var. node_pools ) == 0 ? [] : [1 ]
445
+ content {
446
+ name = " default-pool"
447
+ initial_node_count = var. initial_node_count
448
+
449
+ management {
450
+ auto_repair = lookup (var. cluster_autoscaling , " auto_repair" , true )
451
+ auto_upgrade = lookup (var. cluster_autoscaling , " auto_upgrade" , true )
452
+ }
453
+
454
+ node_config {
455
+ image_type = lookup (var. node_pools [0 ], " image_type" , " COS_CONTAINERD" )
456
+ machine_type = lookup (var. node_pools [0 ], " machine_type" , " e2-medium" )
457
+ min_cpu_platform = lookup (var. node_pools [0 ], " min_cpu_platform" , " " )
458
+ enable_confidential_storage = lookup (var. node_pools [0 ], " enable_confidential_storage" , false )
459
+ disk_type = lookup (var. node_pools [0 ], " disk_type" , null )
460
+ dynamic "gcfs_config" {
461
+ for_each = lookup (var. node_pools [0 ], " enable_gcfs" , null ) != null ? [var . node_pools [0 ]. enable_gcfs ] : []
462
+ content {
463
+ enabled = gcfs_config. value
464
+ }
461
465
}
462
- }
463
466
464
- dynamic "gvnic" {
465
- for_each = lookup (var. node_pools [0 ], " enable_gvnic" , false ) ? [true ] : []
466
- content {
467
- enabled = gvnic. value
467
+ dynamic "gvnic" {
468
+ for_each = lookup (var. node_pools [0 ], " enable_gvnic" , false ) ? [true ] : []
469
+ content {
470
+ enabled = gvnic. value
471
+ }
468
472
}
469
- }
470
473
471
- dynamic "fast_socket" {
472
- for_each = lookup (var. node_pools [0 ], " enable_fast_socket" , null ) != null ? [var . node_pools [0 ]. enable_fast_socket ] : []
473
- content {
474
- enabled = fast_socket. value
474
+ dynamic "fast_socket" {
475
+ for_each = lookup (var. node_pools [0 ], " enable_fast_socket" , null ) != null ? [var . node_pools [0 ]. enable_fast_socket ] : []
476
+ content {
477
+ enabled = fast_socket. value
478
+ }
475
479
}
476
- }
477
480
478
- dynamic "kubelet_config" {
479
- for_each = length (setintersection (
480
- keys (var. node_pools [0 ]),
481
- [" 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" ]
482
- )) != 0 || var. insecure_kubelet_readonly_port_enabled != null ? [1 ] : []
481
+ dynamic "kubelet_config" {
482
+ for_each = length (setintersection (
483
+ keys (var. node_pools [0 ]),
484
+ [" 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" ]
485
+ )) != 0 || var. insecure_kubelet_readonly_port_enabled != null ? [1 ] : []
483
486
484
- content {
485
- cpu_manager_policy = lookup (var. node_pools [0 ], " cpu_manager_policy" , " static" )
486
- cpu_cfs_quota = lookup (var. node_pools [0 ], " cpu_cfs_quota" , null )
487
- cpu_cfs_quota_period = lookup (var. node_pools [0 ], " cpu_cfs_quota_period" , null )
488
- 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
489
- pod_pids_limit = lookup (var. node_pools [0 ], " pod_pids_limit" , null )
490
- container_log_max_size = lookup (var. node_pools [0 ], " container_log_max_size" , null )
491
- container_log_max_files = lookup (var. node_pools [0 ], " container_log_max_files" , null )
492
- image_gc_low_threshold_percent = lookup (var. node_pools [0 ], " image_gc_low_threshold_percent" , null )
493
- image_gc_high_threshold_percent = lookup (var. node_pools [0 ], " image_gc_high_threshold_percent" , null )
494
- image_minimum_gc_age = lookup (var. node_pools [0 ], " image_minimum_gc_age" , null )
495
- image_maximum_gc_age = lookup (var. node_pools [0 ], " image_maximum_gc_age" , null )
496
- 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)]
487
+ content {
488
+ cpu_manager_policy = lookup (var. node_pools [0 ], " cpu_manager_policy" , " static" )
489
+ cpu_cfs_quota = lookup (var. node_pools [0 ], " cpu_cfs_quota" , null )
490
+ cpu_cfs_quota_period = lookup (var. node_pools [0 ], " cpu_cfs_quota_period" , null )
491
+ 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
492
+ pod_pids_limit = lookup (var. node_pools [0 ], " pod_pids_limit" , null )
493
+ container_log_max_size = lookup (var. node_pools [0 ], " container_log_max_size" , null )
494
+ container_log_max_files = lookup (var. node_pools [0 ], " container_log_max_files" , null )
495
+ image_gc_low_threshold_percent = lookup (var. node_pools [0 ], " image_gc_low_threshold_percent" , null )
496
+ image_gc_high_threshold_percent = lookup (var. node_pools [0 ], " image_gc_high_threshold_percent" , null )
497
+ image_minimum_gc_age = lookup (var. node_pools [0 ], " image_minimum_gc_age" , null )
498
+ image_maximum_gc_age = lookup (var. node_pools [0 ], " image_maximum_gc_age" , null )
499
+ 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)]
500
+ }
497
501
}
498
- }
499
502
500
- dynamic "sole_tenant_config" {
501
- # node_affinity is currently the only member of sole_tenant_config
502
- for_each = lookup (var. node_pools [0 ], " node_affinity" , null ) != null ? [true ] : []
503
- content {
504
- dynamic "node_affinity" {
505
- for_each = lookup (var. node_pools [0 ], " node_affinity" , null ) != null ? [lookup (var. node_pools [0 ], " node_affinity" , null )] : []
506
- content {
507
- key = lookup (jsondecode (node_affinity. value ), " key" , null )
508
- operator = lookup (jsondecode (node_affinity. value ), " operator" , null )
509
- values = lookup (jsondecode (node_affinity. value ), " values" , [])
503
+ dynamic "sole_tenant_config" {
504
+ # node_affinity is currently the only member of sole_tenant_config
505
+ for_each = lookup (var. node_pools [0 ], " node_affinity" , null ) != null ? [true ] : []
506
+ content {
507
+ dynamic "node_affinity" {
508
+ for_each = lookup (var. node_pools [0 ], " node_affinity" , null ) != null ? [lookup (var. node_pools [0 ], " node_affinity" , null )] : []
509
+ content {
510
+ key = lookup (jsondecode (node_affinity. value ), " key" , null )
511
+ operator = lookup (jsondecode (node_affinity. value ), " operator" , null )
512
+ values = lookup (jsondecode (node_affinity. value ), " values" , [])
513
+ }
510
514
}
511
515
}
512
516
}
513
- }
514
517
515
- service_account = lookup (var. node_pools [0 ], " service_account" , local. service_account )
518
+ service_account = lookup (var. node_pools [0 ], " service_account" , local. service_account )
516
519
517
- tags = concat (
518
- lookup (local. node_pools_tags , " default_values" , [true , true ])[0 ] ? [local . cluster_network_tag ] : [],
519
- lookup (local. node_pools_tags , " default_values" , [true , true ])[1 ] ? [" ${ local . cluster_network_tag } -default-pool" ] : [],
520
- lookup (local. node_pools_tags , " all" , []),
521
- lookup (local. node_pools_tags , var. node_pools [0 ]. name , []),
522
- )
520
+ tags = concat (
521
+ lookup (local. node_pools_tags , " default_values" , [true , true ])[0 ] ? [local . cluster_network_tag ] : [],
522
+ lookup (local. node_pools_tags , " default_values" , [true , true ])[1 ] ? [" ${ local . cluster_network_tag } -default-pool" ] : [],
523
+ lookup (local. node_pools_tags , " all" , []),
524
+ lookup (local. node_pools_tags , var. node_pools [0 ]. name , []),
525
+ )
523
526
524
- logging_variant = lookup (var. node_pools [0 ], " logging_variant" , " DEFAULT" )
527
+ logging_variant = lookup (var. node_pools [0 ], " logging_variant" , " DEFAULT" )
525
528
526
- dynamic "workload_metadata_config" {
527
- for_each = local. cluster_node_metadata_config
529
+ dynamic "workload_metadata_config" {
530
+ for_each = local. cluster_node_metadata_config
528
531
529
- content {
530
- mode = workload_metadata_config. value . mode
532
+ content {
533
+ mode = workload_metadata_config. value . mode
534
+ }
531
535
}
532
- }
533
536
534
- metadata = local. node_pools_metadata [" all" ]
537
+ metadata = local. node_pools_metadata [" all" ]
535
538
536
- boot_disk_kms_key = lookup (var. node_pools [0 ], " boot_disk_kms_key" , var. boot_disk_kms_key )
539
+ boot_disk_kms_key = lookup (var. node_pools [0 ], " boot_disk_kms_key" , var. boot_disk_kms_key )
537
540
538
- storage_pools = lookup (var. node_pools [0 ], " storage_pools" , null ) != null ? [var . node_pools [0 ]. storage_pools ] : []
541
+ storage_pools = lookup (var. node_pools [0 ], " storage_pools" , null ) != null ? [var . node_pools [0 ]. storage_pools ] : []
539
542
540
- shielded_instance_config {
541
- enable_secure_boot = lookup (var. node_pools [0 ], " enable_secure_boot" , false )
542
- enable_integrity_monitoring = lookup (var. node_pools [0 ], " enable_integrity_monitoring" , true )
543
- }
543
+ shielded_instance_config {
544
+ enable_secure_boot = lookup (var. node_pools [0 ], " enable_secure_boot" , false )
545
+ enable_integrity_monitoring = lookup (var. node_pools [0 ], " enable_integrity_monitoring" , true )
546
+ }
544
547
545
- local_ssd_encryption_mode = lookup (var. node_pools [0 ], " local_ssd_encryption_mode" , null )
546
- max_run_duration = lookup (var. node_pools [0 ], " max_run_duration" , null )
547
- flex_start = lookup (var. node_pools [0 ], " flex_start" , null )
548
+ local_ssd_encryption_mode = lookup (var. node_pools [0 ], " local_ssd_encryption_mode" , null )
549
+ max_run_duration = lookup (var. node_pools [0 ], " max_run_duration" , null )
550
+ flex_start = lookup (var. node_pools [0 ], " flex_start" , null )
551
+ }
548
552
}
549
553
}
550
554
0 commit comments