@@ -88,6 +88,34 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource {
8888 pluginsdk .ForceNewIfChange ("upgrade_settings.0.undrainable_node_behavior" , func (ctx context.Context , old , new , meta interface {}) bool {
8989 return old != "" && new == ""
9090 }),
91+ func (ctx context.Context , d * pluginsdk.ResourceDiff , meta interface {}) error {
92+ priority := d .Get ("priority" ).(string )
93+ isSpot := priority == string (agentpools .ScaleSetPrioritySpot )
94+
95+ upgradeSettingsRaw := d .Get ("upgrade_settings" ).([]interface {})
96+ if len (upgradeSettingsRaw ) == 0 || upgradeSettingsRaw [0 ] == nil {
97+ return nil
98+ }
99+
100+ upgradeSettings := upgradeSettingsRaw [0 ].(map [string ]interface {})
101+ maxSurgeRaw := upgradeSettings ["max_surge" ].(string )
102+ maxUnavailableRaw := upgradeSettings ["max_unavailable" ].(string )
103+
104+ if isSpot {
105+ if maxSurgeRaw != "" {
106+ return fmt .Errorf ("`max_surge` cannot be set when `priority` is set to `Spot`. Spot pools do not support `max_surge`" )
107+ }
108+ if maxUnavailableRaw != "" {
109+ return fmt .Errorf ("`max_unavailable` cannot be set when `priority` is set to `Spot`. Spot pools do not support `max_unavailable`" )
110+ }
111+ } else {
112+ if maxSurgeRaw == "" && maxUnavailableRaw == "" {
113+ return fmt .Errorf ("either `max_surge` or `max_unavailable` must be specified in `upgrade_settings` when `priority` is not `Spot`" )
114+ }
115+ }
116+
117+ return nil
118+ },
91119 ),
92120 }
93121
@@ -523,11 +551,6 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
523551 spotMaxPrice := d .Get ("spot_max_price" ).(float64 )
524552 t := d .Get ("tags" ).(map [string ]interface {})
525553
526- upgradeSettings , err := expandAgentPoolUpgradeSettings (d .Get ("upgrade_settings" ).([]interface {}), priority )
527- if err != nil {
528- return err
529- }
530-
531554 profile := agentpools.ManagedClusterAgentPoolProfileProperties {
532555 OsType : pointer .To (agentpools .OSType (osType )),
533556 EnableAutoScaling : pointer .To (enableAutoScaling ),
@@ -541,7 +564,7 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
541564 Tags : tags .Expand (t ),
542565 Type : pointer .To (agentpools .AgentPoolTypeVirtualMachineScaleSets ),
543566 VMSize : pointer .To (d .Get ("vm_size" ).(string )),
544- UpgradeSettings : upgradeSettings ,
567+ UpgradeSettings : expandAgentPoolUpgradeSettings ( d . Get ( "upgrade_settings" ).([] interface {}), priority ) ,
545568 WindowsProfile : expandAgentPoolWindowsProfile (d .Get ("windows_profile" ).([]interface {})),
546569
547570 // this must always be sent during creation, but is optional for auto-scaled clusters during update
@@ -885,11 +908,7 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int
885908 if d .HasChange ("upgrade_settings" ) {
886909 upgradeSettingsRaw := d .Get ("upgrade_settings" ).([]interface {})
887910 priority := d .Get ("priority" ).(string )
888- upgradeSettings , err := expandAgentPoolUpgradeSettings (upgradeSettingsRaw , priority )
889- if err != nil {
890- return err
891- }
892- props .UpgradeSettings = upgradeSettings
911+ props .UpgradeSettings = expandAgentPoolUpgradeSettings (upgradeSettingsRaw , priority )
893912 }
894913
895914 if d .HasChange ("scale_down_mode" ) {
@@ -1279,7 +1298,6 @@ func upgradeSettingsSchemaNodePoolResource() *pluginsdk.Schema {
12791298 Optional : true ,
12801299 ValidateFunc : validation .StringIsNotEmpty ,
12811300 ConflictsWith : []string {"upgrade_settings.0.max_unavailable" },
1282- Description : "The maximum number of nodes that can be created during upgrade. This cannot be set when `priority` is set to `Spot`." ,
12831301 },
12841302 "drain_timeout_in_minutes" : {
12851303 Type : pluginsdk .TypeInt ,
@@ -1291,7 +1309,6 @@ func upgradeSettingsSchemaNodePoolResource() *pluginsdk.Schema {
12911309 Optional : true ,
12921310 ValidateFunc : validation .StringIsNotEmpty ,
12931311 ConflictsWith : []string {"upgrade_settings.0.max_surge" },
1294- Description : "The maximum number of nodes that can be unavailable during upgrade. This cannot be set when `priority` is set to `Spot`." ,
12951312 },
12961313 "node_soak_duration_in_minutes" : {
12971314 Type : pluginsdk .TypeInt ,
@@ -1380,10 +1397,10 @@ func expandAgentPoolKubeletConfig(input []interface{}) *agentpools.KubeletConfig
13801397 return result
13811398}
13821399
1383- func expandAgentPoolUpgradeSettings (input []interface {}, priority string ) ( * agentpools.AgentPoolUpgradeSettings , error ) {
1400+ func expandAgentPoolUpgradeSettings (input []interface {}, priority string ) * agentpools.AgentPoolUpgradeSettings {
13841401 setting := & agentpools.AgentPoolUpgradeSettings {}
13851402 if len (input ) == 0 || input [0 ] == nil {
1386- return nil , nil
1403+ return nil
13871404 }
13881405
13891406 v := input [0 ].(map [string ]interface {})
@@ -1392,20 +1409,7 @@ func expandAgentPoolUpgradeSettings(input []interface{}, priority string) (*agen
13921409 maxSurgeRaw := v ["max_surge" ].(string )
13931410 maxUnavailableRaw := v ["max_unavailable" ].(string )
13941411
1395- if isSpot {
1396- if maxSurgeRaw != "" {
1397- return nil , fmt .Errorf ("`max_surge` cannot be set when `priority` is set to `Spot`. Spot pools do not support `max_surge`" )
1398- }
1399- if maxUnavailableRaw != "" {
1400- return nil , fmt .Errorf ("`max_unavailable` cannot be set when `priority` is set to `Spot`. Spot pools do not support `max_unavailable`" )
1401- }
1402- }
1403-
14041412 if ! isSpot {
1405- if maxSurgeRaw == "" && maxUnavailableRaw == "" {
1406- return nil , fmt .Errorf ("either `max_surge` or `max_unavailable` must be specified in `upgrade_settings` when `priority` is not `Spot`" )
1407- }
1408-
14091413 if maxSurgeRaw != "" {
14101414 setting .MaxSurge = pointer .To (maxSurgeRaw )
14111415 setting .MaxUnavailable = pointer .To ("0" )
@@ -1425,7 +1429,7 @@ func expandAgentPoolUpgradeSettings(input []interface{}, priority string) (*agen
14251429 if undrainableNodeBehaviorRaw , ok := v ["undrainable_node_behavior" ].(string ); ok && undrainableNodeBehaviorRaw != "" {
14261430 setting .UndrainableNodeBehavior = pointer .To (agentpools .UndrainableNodeBehavior (undrainableNodeBehaviorRaw ))
14271431 }
1428- return setting , nil
1432+ return setting
14291433}
14301434
14311435func flattenAgentPoolUpgradeSettings (input * agentpools.AgentPoolUpgradeSettings ) []interface {} {
0 commit comments