5
5
"log"
6
6
"time"
7
7
8
- "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-12 -01/compute"
8
+ "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07 -01/compute"
9
9
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
10
10
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
11
11
azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
@@ -282,7 +282,8 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
282
282
resourceGroup := d .Get ("resource_group_name" ).(string )
283
283
name := d .Get ("name" ).(string )
284
284
285
- exists , err := client .Get (ctx , resourceGroup , name )
285
+ // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method
286
+ exists , err := client .Get (ctx , resourceGroup , name , compute .ExpandTypesForGetVMScaleSetsUserData )
286
287
if err != nil {
287
288
if ! utils .ResponseWasNotFound (exists .Response ) {
288
289
return fmt .Errorf ("checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v" , name , resourceGroup , err )
@@ -345,16 +346,16 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
345
346
rollingUpgradePolicy := ExpandVirtualMachineScaleSetRollingUpgradePolicy (rollingUpgradePolicyRaw )
346
347
347
348
if upgradeMode != compute .UpgradeModeAutomatic && len (automaticOSUpgradePolicyRaw ) > 0 {
348
- return fmt .Errorf ("An `automatic_os_upgrade_policy` block cannot be specified when `upgrade_mode` is not set to `Automatic`" )
349
+ return fmt .Errorf ("an `automatic_os_upgrade_policy` block cannot be specified when `upgrade_mode` is not set to `Automatic`" )
349
350
}
350
351
351
352
shouldHaveRollingUpgradePolicy := upgradeMode == compute .UpgradeModeAutomatic || upgradeMode == compute .UpgradeModeRolling
352
353
if ! shouldHaveRollingUpgradePolicy && len (rollingUpgradePolicyRaw ) > 0 {
353
- return fmt .Errorf ("A `rolling_upgrade_policy` block cannot be specified when `upgrade_mode` is set to %q" , string (upgradeMode ))
354
+ return fmt .Errorf ("a `rolling_upgrade_policy` block cannot be specified when `upgrade_mode` is set to %q" , string (upgradeMode ))
354
355
}
355
356
shouldHaveRollingUpgradePolicy = upgradeMode == compute .UpgradeModeRolling
356
357
if shouldHaveRollingUpgradePolicy && len (rollingUpgradePolicyRaw ) == 0 {
357
- return fmt .Errorf ("A `rolling_upgrade_policy` block must be specified when `upgrade_mode` is set to %q" , string (upgradeMode ))
358
+ return fmt .Errorf ("a `rolling_upgrade_policy` block must be specified when `upgrade_mode` is set to %q" , string (upgradeMode ))
358
359
}
359
360
360
361
secretsRaw := d .Get ("secret" ).([]interface {})
@@ -461,16 +462,16 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
461
462
462
463
// Azure API: "Authentication using either SSH or by user name and password must be enabled in Linux profile."
463
464
if disablePasswordAuthentication && virtualMachineProfile .OsProfile .AdminPassword == nil && len (sshKeys ) == 0 {
464
- return fmt .Errorf ("At least one SSH key must be specified if `disable_password_authentication` is enabled" )
465
+ return fmt .Errorf ("at least one SSH key must be specified if `disable_password_authentication` is enabled" )
465
466
}
466
467
467
468
if evictionPolicyRaw , ok := d .GetOk ("eviction_policy" ); ok {
468
469
if virtualMachineProfile .Priority != compute .VirtualMachinePriorityTypesSpot {
469
- return fmt .Errorf ("An `eviction_policy` can only be specified when `priority` is set to `Spot`" )
470
+ return fmt .Errorf ("an `eviction_policy` can only be specified when `priority` is set to `Spot`" )
470
471
}
471
472
virtualMachineProfile .EvictionPolicy = compute .VirtualMachineEvictionPolicyTypes (evictionPolicyRaw .(string ))
472
473
} else if priority == compute .VirtualMachinePriorityTypesSpot {
473
- return fmt .Errorf ("An `eviction_policy` must be specified when `priority` is set to `Spot`" )
474
+ return fmt .Errorf ("an `eviction_policy` must be specified when `priority` is set to `Spot`" )
474
475
}
475
476
476
477
if v , ok := d .GetOk ("terminate_notification" ); ok {
@@ -501,6 +502,10 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
501
502
SinglePlacementGroup : utils .Bool (d .Get ("single_placement_group" ).(bool )),
502
503
VirtualMachineProfile : & virtualMachineProfile ,
503
504
UpgradePolicy : & upgradePolicy ,
505
+ // OrchestrationMode needs to be hardcoded to Uniform, for the
506
+ // standard VMSS resource, since virtualMachineProfile is now supported
507
+ // in both VMSS and Orchestrated VMSS...
508
+ OrchestrationMode : compute .OrchestrationModeUniform ,
504
509
ScaleInPolicy : & compute.ScaleInPolicy {
505
510
Rules : & []compute.VirtualMachineScaleSetScaleInRules {compute .VirtualMachineScaleSetScaleInRules (scaleInPolicy )},
506
511
},
@@ -539,7 +544,8 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
539
544
log .Printf ("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created" , name , resourceGroup )
540
545
541
546
log .Printf ("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q).." , name , resourceGroup )
542
- resp , err := client .Get (ctx , resourceGroup , name )
547
+ // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method
548
+ resp , err := client .Get (ctx , resourceGroup , name , compute .ExpandTypesForGetVMScaleSetsUserData )
543
549
if err != nil {
544
550
return fmt .Errorf ("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v" , name , resourceGroup , err )
545
551
}
@@ -565,7 +571,8 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta i
565
571
updateInstances := false
566
572
567
573
// retrieve
568
- existing , err := client .Get (ctx , id .ResourceGroup , id .Name )
574
+ // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method
575
+ existing , err := client .Get (ctx , id .ResourceGroup , id .Name , compute .ExpandTypesForGetVMScaleSetsUserData )
569
576
if err != nil {
570
577
return fmt .Errorf ("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v" , id .Name , id .ResourceGroup , err )
571
578
}
@@ -867,7 +874,8 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int
867
874
return err
868
875
}
869
876
870
- resp , err := client .Get (ctx , id .ResourceGroup , id .Name )
877
+ // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method
878
+ resp , err := client .Get (ctx , id .ResourceGroup , id .Name , compute .ExpandTypesForGetVMScaleSetsUserData )
871
879
if err != nil {
872
880
if utils .ResponseWasNotFound (resp .Response ) {
873
881
log .Printf ("[DEBUG] Linux Virtual Machine Scale Set %q was not found in Resource Group %q - removing from state!" , id .Name , id .ResourceGroup )
@@ -1074,7 +1082,8 @@ func resourceLinuxVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta i
1074
1082
return err
1075
1083
}
1076
1084
1077
- resp , err := client .Get (ctx , id .ResourceGroup , id .Name )
1085
+ // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method
1086
+ resp , err := client .Get (ctx , id .ResourceGroup , id .Name , compute .ExpandTypesForGetVMScaleSetsUserData )
1078
1087
if err != nil {
1079
1088
if utils .ResponseWasNotFound (resp .Response ) {
1080
1089
return nil
0 commit comments