azurerm_orchestrated_virtual_machine_scale_set - support for the upgrade_mode and rolling_upgrade_policy properties#28354
Conversation
azurerm_orchestrated_virtual_machine_scale_set - support upgrade_mode and rolling_upgrade_policyazurerm_orchestrated_virtual_machine_scale_set - support for the property upgrade_mode and rolling_upgrade_policy
azurerm_orchestrated_virtual_machine_scale_set - support for the property upgrade_mode and rolling_upgrade_policyazurerm_orchestrated_virtual_machine_scale_set - support for the upgrade_mode and rolling_upgrade_policy properties
|
@rcskosir anything we can do to get a reviewer on this PR :) |
sreallymatt
left a comment
There was a problem hiding this comment.
Hi @ms-zhenhua, I've left a couple comments inline for you to review, thanks!
internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go
Show resolved
Hide resolved
sreallymatt
left a comment
There was a problem hiding this comment.
Hi @ms-zhenhua, I've gone back over this PR and have left some comments, there was also a panic when I ran the tests for this PR. Would you mind taking a look?
| hasHealthExtension := false | ||
| if v, ok := diff.GetOk("extension"); ok { | ||
| var err error | ||
| _, hasHealthExtension, err = expandOrchestratedVirtualMachineScaleSetExtensions(v.(*pluginsdk.Set).List()) |
There was a problem hiding this comment.
When running the tests there was a panic that seems like it may be related to this call to expandOrchestratedVirtualMachineScaleSetExtensions
The test that failed: TestAccOrchestratedVirtualMachineScaleSet_extensionProtectedSettingsFromKeyVault
Could you investigate?
There was a problem hiding this comment.
apologies, my mistake. I had intended to make this validation take effect in plan stage. However, the value of expandProtectedSettingsFromKeyVaultVMSS does not exist in plan stage. Seems it is unsafe to check non-primitive type of attributes in plan stage, I have moved the validation into Create method. Thank you for pointing out this issue.
|
|
||
| // Virtual Machine Scale Set with Flexible Orchestration Mode and 'Rolling' upgradeMode must have Health Extension Present | ||
| if upgradeMode == virtualmachinescalesets.UpgradeModeRolling && !hasHealthExtension { | ||
| return fmt.Errorf("a health extension must be specified when `upgrade_mode` is set to Rolling") |
There was a problem hiding this comment.
Minor suggestion to stay consistent with how we usually format error messages, will require an update to the test on ln313 of orchestrated_virtual_machine_scale_set_resource_other_test.go as well
| return fmt.Errorf("a health extension must be specified when `upgrade_mode` is set to Rolling") | |
| return fmt.Errorf("a health extension must be specified when `upgrade_mode` is set to `Rolling`") |
There was a problem hiding this comment.
updated. The new code is in resourceOrchestratedVirtualMachineScaleSetCreate method.
| rollingUpgradePolicyRaw := d.Get("rolling_upgrade_policy").([]interface{}) | ||
| rollingUpgradePolicy, err := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw, len(zones) > 0, false) |
There was a problem hiding this comment.
Since it doesn't look like rollingUpgradePolicyRaw is used elsewhere in this function we can simplify this
| rollingUpgradePolicyRaw := d.Get("rolling_upgrade_policy").([]interface{}) | |
| rollingUpgradePolicy, err := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw, len(zones) > 0, false) | |
| rollingUpgradePolicy, err := ExpandVirtualMachineScaleSetRollingUpgradePolicy(d.Get("rolling_upgrade_policy").([]interface{}), len(zones) > 0, false) |
There was a problem hiding this comment.
updated. Thanks.
| rollingUpgradePolicyRaw := d.Get("rolling_upgrade_policy").([]interface{}) | ||
| rollingUpgradePolicy, err := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw, len(zones) > 0, false) | ||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
Could we wrap this error?
| return err | |
| return fmt.Errorf("expanding `rolling_upgrade_policy`: %+v", err) |
There was a problem hiding this comment.
updated. Thanks
| if existing.Model.Properties.UpgradePolicy == nil { | ||
| upgradePolicy = virtualmachinescalesets.UpgradePolicy{ | ||
| Mode: pointer.To(virtualmachinescalesets.UpgradeMode(d.Get("upgrade_mode").(string))), | ||
| } | ||
| } else { | ||
| upgradePolicy = *existing.Model.Properties.UpgradePolicy | ||
| upgradePolicy.Mode = pointer.To(virtualmachinescalesets.UpgradeMode(d.Get("upgrade_mode").(string))) | ||
| } |
There was a problem hiding this comment.
I think we could simplify this to the below, what do you think?
| if existing.Model.Properties.UpgradePolicy == nil { | |
| upgradePolicy = virtualmachinescalesets.UpgradePolicy{ | |
| Mode: pointer.To(virtualmachinescalesets.UpgradeMode(d.Get("upgrade_mode").(string))), | |
| } | |
| } else { | |
| upgradePolicy = *existing.Model.Properties.UpgradePolicy | |
| upgradePolicy.Mode = pointer.To(virtualmachinescalesets.UpgradeMode(d.Get("upgrade_mode").(string))) | |
| } | |
| if existing.Model.Properties.UpgradePolicy != nil { | |
| upgradePolicy = *existing.Model.Properties.UpgradePolicy | |
| } | |
| upgradePolicy.Mode = pointer.To(virtualmachinescalesets.UpgradeMode(d.Get("upgrade_mode").(string))) |
There was a problem hiding this comment.
updated. Thanks.
| zones := zones.ExpandUntyped(d.Get("zones").(*schema.Set).List()) | ||
| rollingUpgradePolicy, err := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingRaw, len(zones) > 0, false) | ||
| if err != nil { | ||
| return err |
There was a problem hiding this comment.
could we wrap this error message?
| return err | |
| return fmt.Errorf("expanding `rolling_upgrade_policy`: %+v", err) |
There was a problem hiding this comment.
updated. Thanks.
| data.ResourceTest(t, r, []acceptance.TestStep{ | ||
| { | ||
| Config: r.otherRollingWithoutHealthExtension(data), | ||
| ExpectError: regexp.MustCompile("a health extension must be specified when `upgrade_mode` is set to Rolling"), |
There was a problem hiding this comment.
| ExpectError: regexp.MustCompile("a health extension must be specified when `upgrade_mode` is set to Rolling"), | |
| ExpectError: regexp.MustCompile("a health extension must be specified when `upgrade_mode` is set to `Rolling`"), |
There was a problem hiding this comment.
updated. Thanks.
|
|
||
| * `termination_notification` - (Optional) A `termination_notification` block as defined below. | ||
|
|
||
| * `upgrade_mode` - (Optional) Specifies how Upgrades (e.g. changing the Image/SKU) should be performed to Virtual Machine Instances. Possible values are `Automatic`, `Manual` and `Rolling`. Defaults to `Manual`. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
| * `upgrade_mode` - (Optional) Specifies how Upgrades (e.g. changing the Image/SKU) should be performed to Virtual Machine Instances. Possible values are `Automatic`, `Manual` and `Rolling`. Defaults to `Manual`. Changing this forces a new resource to be created. | |
| * `upgrade_mode` - (Optional) Specifies how upgrades (e.g. changing the Image/SKU) should be performed to Virtual Machine Instances. Possible values are `Automatic`, `Manual` and `Rolling`. Defaults to `Manual`. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
updated. Thanks.
|
|
||
| * `proximity_placement_group_id` - (Optional) The ID of the Proximity Placement Group which the Virtual Machine should be assigned to. Changing this forces a new resource to be created. | ||
|
|
||
| * `rolling_upgrade_policy` - (Optional) A `rolling_upgrade_policy` block as defined below. This is Required and can only be specified when `upgrade_mode` is set to `Automatic` or `Rolling`. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
I think this might make it more clear that this cannot be specified only when upgrade_mode is manual and required otherwise?
| * `rolling_upgrade_policy` - (Optional) A `rolling_upgrade_policy` block as defined below. This is Required and can only be specified when `upgrade_mode` is set to `Automatic` or `Rolling`. Changing this forces a new resource to be created. | |
| * `rolling_upgrade_policy` - (Optional) A `rolling_upgrade_policy` block as defined below. This is Required when `upgrade_mode` is set to `Automatic` or `Rolling` and cannot be specified when `upgrade_mode` is set to `Manual`. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
since it is not required by Automatic, I updated it as below:
rolling_upgrade_policy- (Optional) Arolling_upgrade_policyblock as defined below. This is Required whenupgrade_modeis set toRollingand cannot be specified whenupgrade_modeis set toManual. Changing this forces a new resource to be created.
|
|
||
| * `max_unhealthy_upgraded_instance_percent` - (Required) The maximum percentage of upgraded virtual machine instances that can be found to be in an unhealthy state. This check will happen after each batch is upgraded. If this percentage is ever exceeded, the rolling update aborts. | ||
|
|
||
| * `pause_time_between_batches` - (Required) The wait time between completing the update for all virtual machines in one batch and starting the next batch. The time duration should be specified in ISO 8601 format. |
There was a problem hiding this comment.
| * `pause_time_between_batches` - (Required) The wait time between completing the update for all virtual machines in one batch and starting the next batch. The time duration should be specified in ISO 8601 format. | |
| * `pause_time_between_batches` - (Required) The wait time between completing the update for all virtual machines in one batch and starting the next batch. The time duration should be specified in ISO 8601 duration format. |
There was a problem hiding this comment.
updated. Thanks.
|
Hi @sreallymatt , Thank you for the review. I have resolved all the comments. Besides, I set a default value for |
sreallymatt
left a comment
There was a problem hiding this comment.
Thanks for making those changes @ms-zhenhua, I left one comment on the CustomizeDiff for your consideration
| shouldHaveRollingUpgradePolicy := upgradeMode == virtualmachinescalesets.UpgradeModeAutomatic || upgradeMode == virtualmachinescalesets.UpgradeModeRolling | ||
| if !shouldHaveRollingUpgradePolicy && len(rollingUpgradePolicyRaw) > 0 { | ||
| return fmt.Errorf("a `rolling_upgrade_policy` block cannot be specified when `upgrade_mode` is set to %q", string(upgradeMode)) | ||
| } | ||
| shouldHaveRollingUpgradePolicy = upgradeMode == virtualmachinescalesets.UpgradeModeRolling | ||
| if shouldHaveRollingUpgradePolicy && len(rollingUpgradePolicyRaw) == 0 { | ||
| return fmt.Errorf("a `rolling_upgrade_policy` block must be specified when `upgrade_mode` is set to %q", string(upgradeMode)) | ||
| } |
There was a problem hiding this comment.
I think this might be a little more clear if we're explicit about what we're checking for rather than checking for the inverse of upgradeMode == virtualmachinescalesets.UpgradeModeAutomatic || upgradeMode == virtualmachinescalesets.UpgradeModeRolling, WDYT?
| shouldHaveRollingUpgradePolicy := upgradeMode == virtualmachinescalesets.UpgradeModeAutomatic || upgradeMode == virtualmachinescalesets.UpgradeModeRolling | |
| if !shouldHaveRollingUpgradePolicy && len(rollingUpgradePolicyRaw) > 0 { | |
| return fmt.Errorf("a `rolling_upgrade_policy` block cannot be specified when `upgrade_mode` is set to %q", string(upgradeMode)) | |
| } | |
| shouldHaveRollingUpgradePolicy = upgradeMode == virtualmachinescalesets.UpgradeModeRolling | |
| if shouldHaveRollingUpgradePolicy && len(rollingUpgradePolicyRaw) == 0 { | |
| return fmt.Errorf("a `rolling_upgrade_policy` block must be specified when `upgrade_mode` is set to %q", string(upgradeMode)) | |
| } | |
| if upgradeMode == virtualmachinescalesets.UpgradeModeManual && len(rollingUpgradePolicyRaw) > 0 { | |
| return fmt.Errorf("a `rolling_upgrade_policy` block cannot be specified when `upgrade_mode` is set to `%s`", string(upgradeMode)) | |
| } | |
| if upgradeMode == virtualmachinescalesets.UpgradeModeRolling && len(rollingUpgradePolicyRaw) == 0 { | |
| return fmt.Errorf("a `rolling_upgrade_policy` block must be specified when `upgrade_mode` is set to `%s`", string(upgradeMode)) | |
| } |
There was a problem hiding this comment.
That makes sense. Updated.
|
Hi @sreallymatt , Thanks for your review. I have updated the code. Could you please have another review? |
sreallymatt
left a comment
There was a problem hiding this comment.
Thanks @ms-zhenhua, LGTM!
* new changelog for 4.26.0 * Update CHANGELOG.md #29212 * Update CHANGELOG.md #28786 * Update CHANGELOG.md for #29095 * Update CHANGELOG.md #29225 * Update CHANGELOG.md #29168 * Update CHANGELOG.md #28890 * Update CHANGELOG.md for #28689 * Update CHANGELOG.md #28354 * Update CHANGELOG.md #29240 * Update CHANGELOG.md for #29211 * Update CHANGELOG.md #29214 * Update CHANGELOG.md for #29209 * Update CHANGELOG.md for 28690 * Update CHANGELOG.md for #28577 * Update for #29217 #29144 #29145 * Update CHANGELOG.md for #29185 * prep for release --------- Co-authored-by: sreallymatt <[email protected]> Co-authored-by: catriona-m <[email protected]> Co-authored-by: Wyatt Fry <[email protected]> Co-authored-by: Matthew Frahry <[email protected]> Co-authored-by: Wodans Son <[email protected]> Co-authored-by: stephybun <[email protected]>
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Community Note
Description
Support UpgradePolicy for Flex VMSS.
PR Checklist
For example: “
resource_name_here- description of change e.g. adding propertynew_property_name_here”Changes to existing Resource / Data Source
Testing
--- PASS: TestAccOrchestratedVirtualMachineScaleSet_otherUpgradePolicyErrorValidation (28.76s)
--- PASS: TestAccOrchestratedVirtualMachineScaleSet_otherRollingUpgrade (308.14s)
--- PASS: TestAccOrchestratedVirtualMachineScaleSet_otherUpgradePolicy (349.25s)
PASS
Note: Please follow this doc to run

Register-AzProviderFeature -FeatureName MaxSurgeRollingUpgrade -ProviderNamespace Microsoft.Computeto enableMaxSurge upgradesto makeTestAccOrchestratedVirtualMachineScaleSet_otherUpgradePolicypassChange Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_orchestrated_virtual_machine_scale_set- support for theupgrade_modeandrolling_upgrade_policyproperties [Support for rolling_upgrade_policy in azurerm_orchestrated_virtual_machine_scale_set #28270]This is a (please select all that apply):
Related Issue(s)
Fixes #28270
Note
If this PR changes meaningfully during the course of review please update the title and description as required.