@@ -171,6 +171,7 @@ func resourceContainerCluster() *schema.Resource {
171
171
containerClusterAutopilotCustomizeDiff ,
172
172
containerClusterNodeVersionRemoveDefaultCustomizeDiff ,
173
173
containerClusterNetworkPolicyEmptyCustomizeDiff ,
174
+ containerClusterSurgeSettingsCustomizeDiff ,
174
175
),
175
176
176
177
Timeouts : & schema.ResourceTimeout {
@@ -458,6 +459,12 @@ func resourceContainerCluster() *schema.Resource {
458
459
DiffSuppressFunc : suppressDiffForAutopilot ,
459
460
ValidateFunc : validation .StringInSlice ([]string {"COS_CONTAINERD" , "COS" , "UBUNTU_CONTAINERD" , "UBUNTU" }, false ),
460
461
},
462
+ "min_cpu_platform" : {
463
+ Type : schema .TypeString ,
464
+ Optional : true ,
465
+ DiffSuppressFunc : emptyOrDefaultStringSuppress ("automatic" ),
466
+ Description : `Minimum CPU platform to be used by this instance. The instance may be scheduled on the specified or newer CPU platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell.` ,
467
+ },
461
468
"boot_disk_kms_key" : {
462
469
Type : schema .TypeString ,
463
470
Optional : true ,
@@ -536,6 +543,93 @@ func resourceContainerCluster() *schema.Resource {
536
543
},
537
544
},
538
545
},
546
+ "upgrade_settings" : {
547
+ Type : schema .TypeList ,
548
+ Optional : true ,
549
+ Description : `Specifies the upgrade settings for NAP created node pools` ,
550
+ Computed : true ,
551
+ MaxItems : 1 ,
552
+ Elem : & schema.Resource {
553
+ Schema : map [string ]* schema.Schema {
554
+ "max_surge" : {
555
+ Type : schema .TypeInt ,
556
+ Optional : true ,
557
+ Description : `The maximum number of nodes that can be created beyond the current size of the node pool during the upgrade process.` ,
558
+ },
559
+ "max_unavailable" : {
560
+ Type : schema .TypeInt ,
561
+ Optional : true ,
562
+ Description : `The maximum number of nodes that can be simultaneously unavailable during the upgrade process.` ,
563
+ },
564
+ "strategy" : {
565
+ Type : schema .TypeString ,
566
+ Optional : true ,
567
+ Computed : true ,
568
+ Description : `Update strategy of the node pool.` ,
569
+ ValidateFunc : validation .StringInSlice ([]string {"NODE_POOL_UPDATE_STRATEGY_UNSPECIFIED" , "BLUE_GREEN" , "SURGE" }, false ),
570
+ },
571
+ "blue_green_settings" : {
572
+ Type : schema .TypeList ,
573
+ Optional : true ,
574
+ Computed : true ,
575
+ MaxItems : 1 ,
576
+ Description : `Settings for blue-green upgrade strategy.` ,
577
+ Elem : & schema.Resource {
578
+ Schema : map [string ]* schema.Schema {
579
+ "node_pool_soak_duration" : {
580
+ Type : schema .TypeString ,
581
+ Optional : true ,
582
+ Computed : true ,
583
+ Description : `Time needed after draining entire blue pool. After this period, blue pool will be cleaned up.
584
+
585
+ A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s".` ,
586
+ },
587
+ "standard_rollout_policy" : {
588
+ Type : schema .TypeList ,
589
+ Optional : true ,
590
+ Computed : true ,
591
+ MaxItems : 1 ,
592
+ Description : `Standard policy for the blue-green upgrade.` ,
593
+ Elem : & schema.Resource {
594
+ Schema : map [string ]* schema.Schema {
595
+ "batch_percentage" : {
596
+ Type : schema .TypeFloat ,
597
+ Optional : true ,
598
+ Computed : true ,
599
+ ValidateFunc : validation .FloatBetween (0.0 , 1.0 ),
600
+ ExactlyOneOf : []string {
601
+ "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.blue_green_settings.0.standard_rollout_policy.0.batch_percentage" ,
602
+ "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.blue_green_settings.0.standard_rollout_policy.0.batch_node_count" ,
603
+ },
604
+ Description : `Percentage of the bool pool nodes to drain in a batch. The range of this field should be (0.0, 1.0].` ,
605
+ },
606
+ "batch_node_count" : {
607
+ Type : schema .TypeInt ,
608
+ Optional : true ,
609
+ Computed : true ,
610
+ ExactlyOneOf : []string {
611
+ "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.blue_green_settings.0.standard_rollout_policy.0.batch_percentage" ,
612
+ "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.blue_green_settings.0.standard_rollout_policy.0.batch_node_count" ,
613
+ },
614
+ Description : `Number of blue nodes to drain in a batch.` ,
615
+ },
616
+ "batch_soak_duration" : {
617
+ Type : schema .TypeString ,
618
+ Optional : true ,
619
+ Default : "0s" ,
620
+ Description : `Soak time after each batch gets drained.
621
+
622
+ A duration in seconds with up to nine fractional digits, ending with 's'. Example: "3.5s".` ,
623
+ },
624
+ },
625
+ },
626
+ },
627
+ },
628
+ },
629
+ },
630
+ },
631
+ },
632
+ },
539
633
},
540
634
},
541
635
},
@@ -3448,13 +3542,14 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
3448
3542
config := l [0 ].(map [string ]interface {})
3449
3543
3450
3544
npd := & container.AutoprovisioningNodePoolDefaults {
3451
- OauthScopes : convertStringArr (config ["oauth_scopes" ].([]interface {})),
3452
- ServiceAccount : config ["service_account" ].(string ),
3453
- DiskSizeGb : int64 (config ["disk_size" ].(int )),
3454
- DiskType : config ["disk_type" ].(string ),
3455
- ImageType : config ["image_type" ].(string ),
3456
- BootDiskKmsKey : config ["boot_disk_kms_key" ].(string ),
3457
- Management : expandManagement (config ["management" ]),
3545
+ OauthScopes : convertStringArr (config ["oauth_scopes" ].([]interface {})),
3546
+ ServiceAccount : config ["service_account" ].(string ),
3547
+ DiskSizeGb : int64 (config ["disk_size" ].(int )),
3548
+ DiskType : config ["disk_type" ].(string ),
3549
+ ImageType : config ["image_type" ].(string ),
3550
+ BootDiskKmsKey : config ["boot_disk_kms_key" ].(string ),
3551
+ Management : expandManagement (config ["management" ]),
3552
+ UpgradeSettings : expandUpgradeSettings (config ["upgrade_settings" ]),
3458
3553
}
3459
3554
3460
3555
if v , ok := config ["shielded_instance_config" ]; ok && len (v .([]interface {})) > 0 {
@@ -3465,9 +3560,64 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
3465
3560
}
3466
3561
}
3467
3562
3563
+ cpu := config ["min_cpu_platform" ].(string )
3564
+ // the only way to unset the field is to pass "automatic" as its value
3565
+ if cpu == "" {
3566
+ cpu = "automatic"
3567
+ }
3568
+ npd .MinCpuPlatform = cpu
3569
+
3468
3570
return npd
3469
3571
}
3470
3572
3573
+ func expandUpgradeSettings (configured interface {}) * container.UpgradeSettings {
3574
+ l , ok := configured .([]interface {})
3575
+ if ! ok || l == nil || len (l ) == 0 || l [0 ] == nil {
3576
+ return & container.UpgradeSettings {}
3577
+ }
3578
+ config := l [0 ].(map [string ]interface {})
3579
+
3580
+ upgradeSettings := & container.UpgradeSettings {
3581
+ MaxSurge : int64 (config ["max_surge" ].(int )),
3582
+ MaxUnavailable : int64 (config ["max_unavailable" ].(int )),
3583
+ Strategy : config ["strategy" ].(string ),
3584
+ BlueGreenSettings : expandBlueGreenSettings (config ["blue_green_settings" ]),
3585
+ }
3586
+
3587
+ return upgradeSettings
3588
+ }
3589
+
3590
+ func expandBlueGreenSettings (configured interface {}) * container.BlueGreenSettings {
3591
+ l , ok := configured .([]interface {})
3592
+ if ! ok || l == nil || len (l ) == 0 || l [0 ] == nil {
3593
+ return & container.BlueGreenSettings {}
3594
+ }
3595
+ config := l [0 ].(map [string ]interface {})
3596
+
3597
+ blueGreenSettings := & container.BlueGreenSettings {
3598
+ NodePoolSoakDuration : config ["node_pool_soak_duration" ].(string ),
3599
+ StandardRolloutPolicy : expandStandardRolloutPolicy (config ["standard_rollout_policy" ]),
3600
+ }
3601
+
3602
+ return blueGreenSettings
3603
+ }
3604
+
3605
+ func expandStandardRolloutPolicy (configured interface {}) * container.StandardRolloutPolicy {
3606
+ l , ok := configured .([]interface {})
3607
+ if ! ok || l == nil || len (l ) == 0 || l [0 ] == nil {
3608
+ return & container.StandardRolloutPolicy {}
3609
+ }
3610
+
3611
+ config := l [0 ].(map [string ]interface {})
3612
+ standardRolloutPolicy := & container.StandardRolloutPolicy {
3613
+ BatchPercentage : config ["batch_percentage" ].(float64 ),
3614
+ BatchNodeCount : int64 (config ["batch_node_count" ].(int )),
3615
+ BatchSoakDuration : config ["batch_soak_duration" ].(string ),
3616
+ }
3617
+
3618
+ return standardRolloutPolicy
3619
+ }
3620
+
3471
3621
func expandManagement (configured interface {}) * container.NodeManagement {
3472
3622
l , ok := configured .([]interface {})
3473
3623
if ! ok || l == nil || len (l ) == 0 || l [0 ] == nil {
@@ -4304,9 +4454,49 @@ func flattenAutoProvisioningDefaults(a *container.AutoprovisioningNodePoolDefaul
4304
4454
r ["disk_size" ] = a .DiskSizeGb
4305
4455
r ["disk_type" ] = a .DiskType
4306
4456
r ["image_type" ] = a .ImageType
4457
+ r ["min_cpu_platform" ] = a .MinCpuPlatform
4307
4458
r ["boot_disk_kms_key" ] = a .BootDiskKmsKey
4308
4459
r ["shielded_instance_config" ] = flattenShieldedInstanceConfig (a .ShieldedInstanceConfig )
4309
4460
r ["management" ] = flattenManagement (a .Management )
4461
+ r ["upgrade_settings" ] = flattenUpgradeSettings (a .UpgradeSettings )
4462
+
4463
+ return []map [string ]interface {}{r }
4464
+ }
4465
+
4466
+ func flattenUpgradeSettings (a * container.UpgradeSettings ) []map [string ]interface {} {
4467
+ if a == nil {
4468
+ return nil
4469
+ }
4470
+ r := make (map [string ]interface {})
4471
+ r ["max_surge" ] = a .MaxSurge
4472
+ r ["max_unavailable" ] = a .MaxUnavailable
4473
+ r ["strategy" ] = a .Strategy
4474
+ r ["blue_green_settings" ] = flattenBlueGreenSettings (a .BlueGreenSettings )
4475
+
4476
+ return []map [string ]interface {}{r }
4477
+ }
4478
+
4479
+ func flattenBlueGreenSettings (a * container.BlueGreenSettings ) []map [string ]interface {} {
4480
+ if a == nil {
4481
+ return nil
4482
+ }
4483
+
4484
+ r := make (map [string ]interface {})
4485
+ r ["node_pool_soak_duration" ] = a .NodePoolSoakDuration
4486
+ r ["standard_rollout_policy" ] = flattenStandardRolloutPolicy (a .StandardRolloutPolicy )
4487
+
4488
+ return []map [string ]interface {}{r }
4489
+ }
4490
+
4491
+ func flattenStandardRolloutPolicy (a * container.StandardRolloutPolicy ) []map [string ]interface {} {
4492
+ if a == nil {
4493
+ return nil
4494
+ }
4495
+
4496
+ r := make (map [string ]interface {})
4497
+ r ["batch_percentage" ] = a .BatchPercentage
4498
+ r ["batch_node_count" ] = a .BatchNodeCount
4499
+ r ["batch_soak_duration" ] = a .BatchSoakDuration
4310
4500
4311
4501
return []map [string ]interface {}{r }
4312
4502
}
@@ -4667,3 +4857,20 @@ func BinaryAuthorizationDiffSuppress(k, old, new string, r *schema.ResourceData)
4667
4857
4668
4858
return false
4669
4859
}
4860
+
4861
+ func containerClusterSurgeSettingsCustomizeDiff (_ context.Context , d * schema.ResourceDiff , meta interface {}) error {
4862
+ if v , ok := d .GetOk ("cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.strategy" ); ok {
4863
+ if v != "SURGE" {
4864
+ if _ , maxSurgeIsPresent := d .GetOk ("cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.max_surge" ); maxSurgeIsPresent {
4865
+ return fmt .Errorf ("Surge upgrade settings max_surge/max_unavailable can only be used when strategy is set to SURGE" )
4866
+ }
4867
+ }
4868
+ if v != "SURGE" {
4869
+ if _ , maxSurgeIsPresent := d .GetOk ("cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.max_unavailable" ); maxSurgeIsPresent {
4870
+ return fmt .Errorf ("Surge upgrade settings max_surge/max_unavailable can only be used when strategy is set to SURGE" )
4871
+ }
4872
+ }
4873
+ }
4874
+
4875
+ return nil
4876
+ }
0 commit comments