Skip to content

Commit

Permalink
feat: Update VMSS to default to flexible orchestration mode - `avm/re…
Browse files Browse the repository at this point in the history
…s/compute/virtual-machine-scale-set` (Azure#1819)

- updated to newest API version
- orchestration mode is now selectable
- VMSS now defaults to flexible orchestration mode
- additional parameters to rolling update policy added
- Tests updated

Successful run:
[![avm.res.compute.virtual-machine-scale-set](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine-scale-set.yml/badge.svg?branch=users%2Frahalan%2FUpdateVMSS)](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine-scale-set.yml)
  • Loading branch information
rahalan authored May 3, 2024
1 parent 0c30c69 commit 4e222b9
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 55 deletions.
104 changes: 96 additions & 8 deletions avm/res/compute/virtual-machine-scale-set/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This module deploys a Virtual Machine Scale Set Extension.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Compute/virtualMachineScaleSets/extensions` | [2022-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Compute/2022-11-01/virtualMachineScaleSets/extensions) |
| `Microsoft.Compute/virtualMachineScaleSets/extensions` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Compute/2023-09-01/virtualMachineScaleSets/extensions) |

## Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ param supressFailures bool = false
@description('Required. Indicates whether the extension should be automatically upgraded by the platform if there is a newer version of the extension available.')
param enableAutomaticUpgrade bool

resource virtualMachineScaleSet 'Microsoft.Compute/virtualMachineScaleSets@2022-11-01' existing = {
resource virtualMachineScaleSet 'Microsoft.Compute/virtualMachineScaleSets@2023-09-01' existing = {
name: virtualMachineScaleSetName
}

resource extension 'Microsoft.Compute/virtualMachineScaleSets/extensions@2022-11-01' = {
resource extension 'Microsoft.Compute/virtualMachineScaleSets/extensions@2023-09-01' = {
name: name
parent: virtualMachineScaleSet
properties: {
Expand Down
4 changes: 2 additions & 2 deletions avm/res/compute/virtual-machine-scale-set/extension/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "8948100547542268397"
"templateHash": "1737879623418595926"
},
"name": "Virtual Machine Scale Set Extensions",
"description": "This module deploys a Virtual Machine Scale Set Extension.",
Expand Down Expand Up @@ -86,7 +86,7 @@
"resources": [
{
"type": "Microsoft.Compute/virtualMachineScaleSets/extensions",
"apiVersion": "2022-11-01",
"apiVersion": "2023-09-01",
"name": "[format('{0}/{1}', parameters('virtualMachineScaleSetName'), parameters('name'))]",
"properties": {
"publisher": "[parameters('publisher')]",
Expand Down
47 changes: 38 additions & 9 deletions avm/res/compute/virtual-machine-scale-set/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ param lock lockType
])
param upgradePolicyMode string = 'Manual'

@description('Optional. Allow VMSS to ignore AZ boundaries when constructing upgrade batches. Take into consideration the Update Domain and maxBatchInstancePercent to determine the batch size.')
param enableCrossZoneUpgrade bool = false

@description('Optional. Create new virtual machines to upgrade the scale set, rather than updating the existing virtual machines. Existing virtual machines will be deleted once the new virtual machines are created for each batch.')
param maxSurge bool = false

@description('Optional. Upgrade all unhealthy instances in a scale set before any healthy instances.')
param prioritizeUnhealthyInstances bool = false

@description('Optional. Rollback failed instances to previous model if the Rolling Upgrade policy is violated.')
param rollbackFailedInstancesOnPolicyBreach bool = false

@description('Optional. The maximum percent of total virtual machine instances that will be upgraded simultaneously by the rolling upgrade in one batch. As this is a maximum, unhealthy instances in previous or future batches can cause the percentage of instances in a batch to decrease to ensure higher reliability.')
param maxBatchInstancePercent int = 20

Expand Down Expand Up @@ -177,6 +189,13 @@ param gracePeriod string = 'PT30M'
@maxLength(15)
param vmNamePrefix string = 'vmssvm'

@description('Optional. Specifies the orchestration mode for the virtual machine scale set.')
@allowed([
'Flexible'
'Uniform'
])
param orchestrationMode string = 'Flexible'

@description('Optional. Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified in the request body, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later.')
param provisionVMAgent bool = true

Expand Down Expand Up @@ -393,26 +412,33 @@ resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' =
}
}

resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2022-11-01' = {
resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2023-09-01' = {
name: name
location: location
tags: tags
identity: identity
zones: availabilityZones
properties: {
orchestrationMode: orchestrationMode
proximityPlacementGroup: !empty(proximityPlacementGroupResourceId)
? {
id: proximityPlacementGroupResourceId
}
: null
upgradePolicy: {
mode: upgradePolicyMode
rollingUpgradePolicy: {
maxBatchInstancePercent: maxBatchInstancePercent
maxUnhealthyInstancePercent: maxUnhealthyInstancePercent
maxUnhealthyUpgradedInstancePercent: maxUnhealthyUpgradedInstancePercent
pauseTimeBetweenBatches: pauseTimeBetweenBatches
}
rollingUpgradePolicy: upgradePolicyMode == 'Rolling'
? {
enableCrossZoneUpgrade: enableCrossZoneUpgrade
maxBatchInstancePercent: maxBatchInstancePercent
maxSurge: maxSurge
maxUnhealthyInstancePercent: maxUnhealthyInstancePercent
maxUnhealthyUpgradedInstancePercent: maxUnhealthyUpgradedInstancePercent
pauseTimeBetweenBatches: pauseTimeBetweenBatches
prioritizeUnhealthyInstances: prioritizeUnhealthyInstances
rollbackFailedInstancesOnPolicyBreach: rollbackFailedInstancesOnPolicyBreach
}
: null
automaticOSUpgradePolicy: {
enableAutomaticOSUpgrade: enableAutomaticOSUpgrade
disableAutomaticRollback: disableAutomaticRollback
Expand Down Expand Up @@ -483,6 +509,7 @@ resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2022-11-01' = {
]
}
networkProfile: {
networkApiVersion: (orchestrationMode == 'Flexible') ? '2020-11-01' : null
networkInterfaceConfigurations: [
for (nicConfiguration, index) in nicConfigurations: {
name: '${name}${nicConfiguration.nicSuffix}configuration-${index}'
Expand Down Expand Up @@ -519,8 +546,10 @@ resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2022-11-01' = {
: null
scheduledEventsProfile: scheduledEventsProfile
}
overprovision: overprovision
doNotRunExtensionsOnOverprovisionedVMs: doNotRunExtensionsOnOverprovisionedVMs
overprovision: (orchestrationMode == 'Uniform') ? overprovision : null
doNotRunExtensionsOnOverprovisionedVMs: (orchestrationMode == 'Uniform')
? doNotRunExtensionsOnOverprovisionedVMs
: null
zoneBalance: zoneBalance == 'true' ? zoneBalance : null
platformFaultDomainCount: scaleSetFaultDomain
singlePlacementGroup: singlePlacementGroup
Expand Down
Loading

0 comments on commit 4e222b9

Please sign in to comment.