-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Adding Automatic Zone Placement #28882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds Automatic Zone Placement functionality for Virtual Machine Scale Sets (VMSS) by introducing four new parameters to New-AzVmssConfig, Update-AzVmss, and New-AzVmss cmdlets. The feature enables automatic distribution of VMSS instances across availability zones with configurable constraints, addressing the requirements outlined in the linked design document.
Key changes:
- Added
ZonePlacementPolicyparameter to control automatic zone selection (values: "Any" for VMs, "Auto" for VMSS) - Added
MaxZoneCountparameter to limit the maximum number of zones used when policy is "Auto" - Added
EnableMaxInstancePercentPerZoneswitch andValueMaxInstancePercentPerZoneto control the percentage distribution of VMs per zone - Implemented validation to ensure
Overprovisionis false whenZonePlacementPolicyis specified
Reviewed changes
Copilot reviewed 9 out of 14 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Compute/Compute/ChangeLog.md | Added changelog entry documenting the new parameters, but with incorrect casing |
| src/Compute/Compute/help/New-AzVmss.md | Added documentation for ZonePlacementPolicy parameter in New-AzVmss cmdlet |
| src/Compute/Compute/help/New-AzVmssConfig.md | Added documentation for all four new parameters in New-AzVmssConfig cmdlet |
| src/Compute/Compute/help/Update-AzVmss.md | Added documentation for all four new parameters in Update-AzVmss cmdlet |
| src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/NewAzureRmVmssConfigCommand.cs | Implemented parameter definitions and zone placement logic for config cmdlet, with nested value parameter handling |
| src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs | Implemented parameter definitions and zone placement logic for update cmdlet with critical bugs in parameter type and object assignment |
| src/Compute/Compute/Generated/Models/PSVirtualMachineScaleSet.cs | Added Placement property to the PowerShell model object |
| src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs | Added convenience ZonePlacementPolicy string property for simple parameter set |
| src/Compute/Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs | Added ZonePlacementPolicy parameter to New-AzVmss simple parameter set |
| src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs | Updated VMSS creation strategy to include Placement object with ZonePlacementPolicy |
| src/Compute/Compute.Management.Sdk/Generated/Models/VirtualMachineScaleSetUpdate.cs | Added Placement property to SDK update model |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 | Added comprehensive test covering creation and update scenarios with zone placement parameters |
| src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs | Added test entry point for new zone placement test |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| * Added `-InstantAccessDurationMinutes` parameter to New-AzSnapshotConfig. | ||
| * Added `SecureVMGuestStateSAS` parameter to `Grant-AzSnapshotAccess`. | ||
| * Updated SDK to use 2025-04-01 version of the ComputeRP API for Compute related cmdlets. | ||
| * Added new parameters `ZonePlacementPolicy`, `maxZoneCount`, `enableMaxInstancePercentPerZone`, and `valueMaxInstancePercentPerZone` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Placement. |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter names in the ChangeLog entry should use PascalCase to match the actual cmdlet parameter names. The correct names are:
MaxZoneCount(notmaxZoneCount)EnableMaxInstancePercentPerZone(notenableMaxInstancePercentPerZone)ValueMaxInstancePercentPerZone(notvalueMaxInstancePercentPerZone)
PowerShell parameters are case-insensitive, but the ChangeLog should use the canonical PascalCase naming as defined in the code for consistency with other entries.
| * Added new parameters `ZonePlacementPolicy`, `maxZoneCount`, `enableMaxInstancePercentPerZone`, and `valueMaxInstancePercentPerZone` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS Automatic Zone Placement. | |
| * Added new parameters `ZonePlacementPolicy`, `MaxZoneCount`, `EnableMaxInstancePercentPerZone`, and `ValueMaxInstancePercentPerZone` to `New-AzVmssConfig` and `Update-AzVmss` cmdlets for VMSS (Virtual Machine Scale Set) Automatic Zone Placement. |
| Mandatory = false, | ||
| ValueFromPipelineByPropertyName = true, | ||
| HelpMessage = "Specifies whether maxInstancePercentPerZonePolicy should be enabled on the virtual machine scale set.")] | ||
| public bool EnableMaxInstancePercentPerZone { get; set; } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type for EnableMaxInstancePercentPerZone is inconsistent between cmdlets:
- In
NewAzureRmVmssConfigCommand.cs(line 426): UsesSwitchParameter(correct for PowerShell boolean flags) - In
VirtualMachineScaleSetUpdateMethod.cs(line 483): Usesbool(incorrect)
The parameter should be consistently defined as SwitchParameter in both cmdlets. With a bool type, users would have to specify -EnableMaxInstancePercentPerZone $true instead of the more natural -EnableMaxInstancePercentPerZone switch syntax.
Change line 483 from:
public bool EnableMaxInstancePercentPerZone { get; set; }to:
public SwitchParameter EnableMaxInstancePercentPerZone { get; set; }Also, update the usage on line 1589 from:
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled = this.EnableMaxInstancePercentPerZone;to:
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled = this.EnableMaxInstancePercentPerZone.IsPresent;And similarly on line 2500 for consistency with the config cmdlet pattern.
| public bool EnableMaxInstancePercentPerZone { get; set; } | |
| public SwitchParameter EnableMaxInstancePercentPerZone { get; set; } |
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount = this.MaxZoneCount; | ||
| } | ||
|
|
||
| if (this.IsParameterBound(c => c.EnableMaxInstancePercentPerZone)) | ||
| { | ||
| InitializeZoneAllocationPolicy(); | ||
| if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | ||
| { | ||
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | ||
| } | ||
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled = this.EnableMaxInstancePercentPerZone; | ||
| } | ||
|
|
||
| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | ||
| { | ||
| InitializeZoneAllocationPolicy(); | ||
| if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | ||
| { | ||
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | ||
| } | ||
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the BuildPutObject method, line 2490 incorrectly assigns MaxZoneCount to VirtualMachineScaleSetUpdate instead of VirtualMachineScaleSet. This is inconsistent with the pattern used for ZonePlacementPolicy (line 2473) which correctly uses VirtualMachineScaleSet.Placement.
Change line 2490 from:
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount = this.MaxZoneCount;to:
this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount = this.MaxZoneCount;The same issue affects lines 2496-2500 and 2506-2510 where VirtualMachineScaleSetUpdate should be VirtualMachineScaleSet.
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount = this.MaxZoneCount; | |
| } | |
| if (this.IsParameterBound(c => c.EnableMaxInstancePercentPerZone)) | |
| { | |
| InitializeZoneAllocationPolicy(); | |
| if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | |
| { | |
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | |
| } | |
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled = this.EnableMaxInstancePercentPerZone; | |
| } | |
| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | |
| { | |
| InitializeZoneAllocationPolicy(); | |
| if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | |
| { | |
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | |
| } | |
| this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; | |
| this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount = this.MaxZoneCount; | |
| } | |
| if (this.IsParameterBound(c => c.EnableMaxInstancePercentPerZone)) | |
| { | |
| InitializeZoneAllocationPolicy(); | |
| if (this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | |
| { | |
| this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | |
| } | |
| this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled = this.EnableMaxInstancePercentPerZone; | |
| } | |
| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | |
| { | |
| InitializeZoneAllocationPolicy(); | |
| if (this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | |
| { | |
| this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | |
| } | |
| this.VirtualMachineScaleSet.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; |
| [Parameter( | ||
| Mandatory = false, | ||
| ValueFromPipelineByPropertyName = true, | ||
| HelpMessage = "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set.")] |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help message for the -ValueMaxInstancePercentPerZone parameter is too vague and doesn't clearly explain what the parameter does. It should explain:
- What the percentage value represents (e.g., "The maximum percentage of virtual machines that can be placed in any single availability zone")
- The valid range (e.g., 0-100)
- The behavior when not specified
The current description "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set" is unclear - it sounds like it describes a count rather than a percentage, and doesn't explain how the limit works.
Compare with other percentage parameters in the codebase which provide clearer explanations.
| HelpMessage = "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set.")] | |
| HelpMessage = "Specifies the maximum percentage (0-100) of virtual machines that can be placed in any single availability zone within the virtual machine scale set. If not specified, no limit is applied.")] |
| $vmssConfig = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_D2s_v3" -ZonePlacementPolicy 'Auto' -MaxZoneCount 2 -EnableMaxInstancePercentPerZone -ValueMaxInstancePercentPerZone 50; | ||
|
|
||
| # Configure IP and NIC | ||
| $ipCfg = New-AzVmssIpConfig -Name "ipconfig1" -SubnetId $subnet.Id | ||
| $vmssConfig = Add-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmssConfig ` | ||
| -Name "nicConfig" -Primary $true -IPConfiguration $ipCfg; | ||
|
|
||
| # Configure OS profile | ||
| $vmssConfig = Set-AzVmssOSProfile -VirtualMachineScaleSet $vmssConfig ` | ||
| -ComputerNamePrefix "test" ` | ||
| -AdminUsername $adminUsername ` | ||
| -AdminPassword $password | ||
|
|
||
| # Assert the Automatic Zone Placement from the vmssConfig | ||
| Assert-AreEqual $vmssConfig.Placement.ZonePlacementPolicy 'Auto'; | ||
| Assert-AreEqual $vmssConfig.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount 2; | ||
| Assert-True { $vmssConfig.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled } | ||
|
|
||
| # Create the vmss using the config | ||
| $vmssResult = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig; | ||
|
|
||
| # Assert the Automatic Zone Placement from the vmssResult | ||
| Assert-AreEqual $vmssResult.Placement.ZonePlacementPolicy 'Auto'; | ||
| Assert-AreEqual $vmssResult.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount 2; | ||
| Assert-True { $vmssResult.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test sets -ValueMaxInstancePercentPerZone 50 on line 6190 but never asserts that this value was properly set on the resulting VMSS configuration or created VMSS.
Add assertions after line 6206 and 6214 to verify:
Assert-AreEqual $vmssConfig.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value 50and
Assert-AreEqual $vmssResult.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value 50This ensures the parameter is being correctly passed through to the API.
|
|
||
| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | ||
| { | ||
| vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; | ||
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for setting ValueMaxInstancePercentPerZone is inconsistent between New-AzVmssConfig and Update-AzVmss:
- In
New-AzVmssConfig(lines 1200-1203):ValueMaxInstancePercentPerZoneis only applied ifEnableMaxInstancePercentPerZoneis present, meaning users must specify both parameters together. - In
Update-AzVmss(lines 1592-1600):ValueMaxInstancePercentPerZonecan be set independently.
For consistency and better user experience, New-AzVmssConfig should handle ValueMaxInstancePercentPerZone independently, similar to Update-AzVmss. This would allow users to set the value in separate operations and make the cmdlets behave consistently.
Consider extracting the ValueMaxInstancePercentPerZone logic (lines 1200-1203) outside of the EnableMaxInstancePercentPerZone.IsPresent check:
if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone))
{
if (vResiliencyPolicy == null)
{
vResiliencyPolicy = new ResiliencyPolicy();
}
if (vResiliencyPolicy.ZoneAllocationPolicy == null)
{
vResiliencyPolicy.ZoneAllocationPolicy = new ZoneAllocationPolicy();
}
if (vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null)
{
vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy();
}
vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone;
}| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | |
| { | |
| vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; | |
| } | |
| } | |
| if (this.IsParameterBound(c => c.ValueMaxInstancePercentPerZone)) | |
| { | |
| if (vResiliencyPolicy == null) | |
| { | |
| vResiliencyPolicy = new ResiliencyPolicy(); | |
| } | |
| if (vResiliencyPolicy.ZoneAllocationPolicy == null) | |
| { | |
| vResiliencyPolicy.ZoneAllocationPolicy = new ZoneAllocationPolicy(); | |
| } | |
| if (vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy == null) | |
| { | |
| vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy = new MaxInstancePercentPerZonePolicy(); | |
| } | |
| vResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Value = this.ValueMaxInstancePercentPerZone; |
| ``` | ||
| ### -ValueMaxInstancePercentPerZone | ||
| The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set. |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description for the -ValueMaxInstancePercentPerZone parameter is too vague and doesn't follow the pattern used for other percentage parameters in the codebase. It should explain:
- What the percentage value represents (e.g., "The maximum percentage of virtual machines that can be placed in any single availability zone")
- The valid range (e.g., 0-100)
- The behavior when not specified (if applicable)
Compare with other percentage parameters like -MaxBatchInstancePercent (line 651-653 in Update-AzVmss.md) which provides clear explanation of what the percentage controls and its constraints.
The current description "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set" is unclear - it sounds like it describes a count rather than a percentage, and doesn't explain how the limit works.
| The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set. | |
| Specifies the maximum percentage of virtual machines that can be placed in any single availability zone within the virtual machine scale set. Valid values are 0 to 100. If not specified, placement is not restricted by zone. |
| ``` | ||
| ### -ValueMaxInstancePercentPerZone | ||
| The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set. |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description for the -ValueMaxInstancePercentPerZone parameter is too vague and doesn't follow the pattern used for other percentage parameters in the codebase. It should explain:
- What the percentage value represents (e.g., "The maximum percentage of virtual machines that can be placed in any single availability zone")
- The valid range (e.g., 0-100)
- The behavior when not specified (if applicable)
Compare with other percentage parameters like -RegularPriorityPercentage (line 922 in New-AzVmssConfig.md) which provides clear explanation of what the percentage controls.
The current description "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set" is unclear - it sounds like it describes a count rather than a percentage, and doesn't explain how the limit works.
| The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set. | |
| Specifies the maximum percentage of virtual machines (VMs) that can be placed in any single availability zone within the scale set. Valid values are from 0 to 100. If not specified, placement is not restricted by percentage per zone. |
| [Parameter( | ||
| Mandatory = false, | ||
| ValueFromPipelineByPropertyName = true, | ||
| HelpMessage = "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set.")] |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help message for the -ValueMaxInstancePercentPerZone parameter is too vague and doesn't clearly explain what the parameter does. It should explain:
- What the percentage value represents (e.g., "The maximum percentage of virtual machines that can be placed in any single availability zone")
- The valid range (e.g., 0-100)
- The behavior when not specified
The current description "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set" is unclear - it sounds like it describes a count rather than a percentage, and doesn't explain how the limit works.
Compare with other percentage parameters in the codebase which provide clearer explanations.
| HelpMessage = "The configuration parameters used to limit the number of virtual machines per availability zone in the virtual machine scale set.")] | |
| HelpMessage = "Specifies the maximum percentage (0-100) of virtual machines that can be placed in any single availability zone in the scale set. Valid values are 0 to 100. If not specified, there is no limit on the percentage of instances per zone.")] |
| <# | ||
| .SYNOPSIS | ||
| Test Virtual Machine Scale Set Automatic Zone Placement feature | ||
| #> | ||
| function Test-VirtualMachineScaleSetAutomaticZonePlacement | ||
| { | ||
| # Setup | ||
| $rgname = Get-ComputeTestResourceName | ||
|
|
||
| try | ||
| { | ||
| # Common | ||
| $loc = "eastus2euap"; | ||
| $vmssName = "vmssAutoZonePlacement" + $rgname; | ||
| $vnetName = "vnetAutoZonePlacement" + $rgname; | ||
| $subnetName = "subnetAutoZonePlacement" + $rgname; | ||
| $adminUsername = Get-ComputeTestResourceName; | ||
| $password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force; | ||
| $cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $password); | ||
| $linuxImage = "Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest" | ||
| $domainNameLabel1 = "d1" + $rgname; | ||
|
|
||
| # Create resource group | ||
| New-AzResourceGroup -Name $rgname -Location $loc -Force | ||
|
|
||
|
|
||
| # Create using simple parameter and New-AzVmss | ||
| $vmss = New-AzVmss -ResourceGroupName $rgname -Location $loc -Credential $cred -VMScaleSetName 'testvmss2' -DomainNameLabel $domainNameLabel1 -Image $linuxImage -ZonePlacementPolicy 'Auto' | ||
|
|
||
| # Verify ZonePlacementPolicy successfully set | ||
| Assert-AreEqual $vmss.Placement.ZonePlacementPolicy 'Auto' | ||
|
|
||
| # Create VNet and Subnet | ||
| $vnetAddressPrefix = "10.0.0.0/16"; | ||
| $subnetAddressPrefix = "10.0.0.0/24"; | ||
| $subnetConfig = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $subnetAddressPrefix; | ||
| $vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddressPrefix -Subnet $subnetConfig; | ||
|
|
||
| # Get subnet object | ||
| $subnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzVirtualNetworkSubnetConfig -Name $subnetName | ||
|
|
||
| # VMSS Config | ||
| $vmssConfig = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_D2s_v3" -ZonePlacementPolicy 'Auto' -MaxZoneCount 2 -EnableMaxInstancePercentPerZone -ValueMaxInstancePercentPerZone 50; | ||
|
|
||
| # Configure IP and NIC | ||
| $ipCfg = New-AzVmssIpConfig -Name "ipconfig1" -SubnetId $subnet.Id | ||
| $vmssConfig = Add-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmssConfig ` | ||
| -Name "nicConfig" -Primary $true -IPConfiguration $ipCfg; | ||
|
|
||
| # Configure OS profile | ||
| $vmssConfig = Set-AzVmssOSProfile -VirtualMachineScaleSet $vmssConfig ` | ||
| -ComputerNamePrefix "test" ` | ||
| -AdminUsername $adminUsername ` | ||
| -AdminPassword $password | ||
|
|
||
| # Assert the Automatic Zone Placement from the vmssConfig | ||
| Assert-AreEqual $vmssConfig.Placement.ZonePlacementPolicy 'Auto'; | ||
| Assert-AreEqual $vmssConfig.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount 2; | ||
| Assert-True { $vmssConfig.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled } | ||
|
|
||
| # Create the vmss using the config | ||
| $vmssResult = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig; | ||
|
|
||
| # Assert the Automatic Zone Placement from the vmssResult | ||
| Assert-AreEqual $vmssResult.Placement.ZonePlacementPolicy 'Auto'; | ||
| Assert-AreEqual $vmssResult.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount 2; | ||
| Assert-True { $vmssResult.ResiliencyPolicy.ZoneAllocationPolicy.MaxInstancePercentPerZonePolicy.Enabled } | ||
|
|
||
| # Update vmss | ||
| $vmssUpdate = Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -MaxZoneCount 3 | ||
|
|
||
| Assert-AreEqual $vmssUpdate.ResiliencyPolicy.ZoneAllocationPolicy.MaxZoneCount 3; | ||
| } | ||
| finally | ||
| { | ||
| # Cleanup | ||
| Clean-ResourceGroup $rgname | ||
| } | ||
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should include validation of the overprovision constraint that prevents using ZonePlacementPolicy with Overprovision = true. The implementation throws an ArgumentException when both are specified (lines 1160-1163 in NewAzureRmVmssConfigCommand.cs and lines 1565-1568, 2476-2479 in VirtualMachineScaleSetUpdateMethod.cs).
Consider adding a negative test case that verifies this validation, such as:
# Test that overprovision validation works
Assert-ThrowsContains {
New-AzVmssConfig -Location $loc -ZonePlacementPolicy 'Auto' -Overprovision $true
} "Overprovision must be false"This ensures the validation logic is working correctly and documents the constraint for future maintainers.
Description
Adding four new parameters to New-AzVmssConfig and Update-AzVmss, as requested in this design: https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/1510
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.