Skip to content

Commit

Permalink
fix: comply with WAF test for maintenance configurations (#2462)
Browse files Browse the repository at this point in the history
Added the possibility to deploy configuration assignments to a VM and
updated the tests (default and WAF aligned) to utilize that

"Successful" run:
[![avm.res.compute.virtual-machine](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg?branch=users%2Frahalan%2FUpdateVM)](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml)

reason for being red: I am not allowed to deploy nVidia VMs in my tenant
due to policy restrictions
  • Loading branch information
rahalan authored Jun 21, 2024
1 parent 7dbe747 commit a930335
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
18 changes: 18 additions & 0 deletions avm/res/compute/virtual-machine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This module deploys a Virtual Machine with one or multiple NICs and optionally o
| `Microsoft.DevTestLab/schedules` | [2018-09-15](https://learn.microsoft.com/en-us/azure/templates/Microsoft.DevTestLab/2018-09-15/schedules) |
| `Microsoft.GuestConfiguration/guestConfigurationAssignments` | [2020-06-25](https://learn.microsoft.com/en-us/azure/templates/Microsoft.GuestConfiguration/2020-06-25/guestConfigurationAssignments) |
| `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) |
| `Microsoft.Maintenance/configurationAssignments` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Maintenance/2023-04-01/configurationAssignments) |
| `Microsoft.Network/networkInterfaces` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-04-01/networkInterfaces) |
| `Microsoft.Network/publicIPAddresses` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-09-01/publicIPAddresses) |
| `Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems` | [2023-01-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.RecoveryServices/2023-01-01/vaults/backupFabrics/protectionContainers/protectedItems) |
Expand Down Expand Up @@ -1039,6 +1040,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
backupPolicyName: '<backupPolicyName>'
backupVaultName: '<backupVaultName>'
backupVaultResourceGroup: '<backupVaultResourceGroup>'
bypassPlatformSafetyChecksOnUserSchedule: true
computerName: 'winvm1'
dataDisks: [
{
Expand Down Expand Up @@ -1166,6 +1168,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
kind: 'CanNotDelete'
name: 'myCustomLockName'
}
maintenanceConfigurationResourceId: '<maintenanceConfigurationResourceId>'
managedIdentities: {
systemAssigned: true
userAssignedResourceIds: [
Expand Down Expand Up @@ -1334,6 +1337,9 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
"backupVaultResourceGroup": {
"value": "<backupVaultResourceGroup>"
},
"bypassPlatformSafetyChecksOnUserSchedule": {
"value": true
},
"computerName": {
"value": "winvm1"
},
Expand Down Expand Up @@ -1491,6 +1497,9 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
"name": "myCustomLockName"
}
},
"maintenanceConfigurationResourceId": {
"value": "<maintenanceConfigurationResourceId>"
},
"managedIdentities": {
"value": {
"systemAssigned": true,
Expand Down Expand Up @@ -3137,6 +3146,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
| [`licenseType`](#parameter-licensetype) | string | Specifies that the image or disk that is being used was licensed on-premises. |
| [`location`](#parameter-location) | string | Location for all resources. |
| [`lock`](#parameter-lock) | object | The lock settings of the service. |
| [`maintenanceConfigurationResourceId`](#parameter-maintenanceconfigurationresourceid) | string | The resource Id of a maintenance configuration for this VM. |
| [`managedIdentities`](#parameter-managedidentities) | object | The managed identity definition for this resource. The system-assigned managed identity will automatically be enabled if extensionAadJoinConfig.enabled = "True". |
| [`maxPriceForLowPriorityVm`](#parameter-maxpriceforlowpriorityvm) | string | Specifies the maximum price you are willing to pay for a low priority VM/VMSS. This price is in US Dollars. |
| [`patchAssessmentMode`](#parameter-patchassessmentmode) | string | VM guest patching assessment mode. Set it to 'AutomaticByPlatform' to enable automatically check for updates every 24 hours. |
Expand Down Expand Up @@ -3919,6 +3929,14 @@ Specify the name of lock.
- Required: No
- Type: string

### Parameter: `maintenanceConfigurationResourceId`

The resource Id of a maintenance configuration for this VM.

- Required: No
- Type: string
- Default: `''`

### Parameter: `managedIdentities`

The managed identity definition for this resource. The system-assigned managed identity will automatically be enabled if extensionAadJoinConfig.enabled = "True".
Expand Down
13 changes: 13 additions & 0 deletions avm/res/compute/virtual-machine/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ param backupPolicyName string = 'DefaultPolicy'
@description('Optional. The configuration for auto-shutdown.')
param autoShutdownConfig object = {}

@description('Optional. The resource Id of a maintenance configuration for this VM.')
param maintenanceConfigurationResourceId string = ''

// Child resources
@description('Optional. Specifies whether extension operations should be allowed on the virtual machine. This may only be set to False when no extensions are present on the virtual machine.')
param allowExtensionOperations bool = true
Expand Down Expand Up @@ -607,6 +610,16 @@ resource vm 'Microsoft.Compute/virtualMachines@2023-09-01' = {
]
}

resource vm_configurationAssignment 'Microsoft.Maintenance/configurationAssignments@2023-04-01' = if (!empty(maintenanceConfigurationResourceId)) {
name: '${vm.name}assignment'
location: location
properties: {
maintenanceConfigurationId: maintenanceConfigurationResourceId
resourceId: vm.id
}
scope: vm
}

resource vm_configurationProfileAssignment 'Microsoft.Automanage/configurationProfileAssignments@2022-05-04' = if (!empty(configurationProfile)) {
name: 'default'
properties: {
Expand Down
24 changes: 23 additions & 1 deletion avm/res/compute/virtual-machine/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.26.54.24096",
"templateHash": "5608164188870152623"
"templateHash": "8007594709688742996"
},
"name": "Virtual Machines",
"description": "This module deploys a Virtual Machine with one or multiple NICs and optionally one or multiple public IPs.",
Expand Down Expand Up @@ -567,6 +567,13 @@
"description": "Optional. The configuration for auto-shutdown."
}
},
"maintenanceConfigurationResourceId": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Optional. The resource Id of a maintenance configuration for this VM."
}
},
"allowExtensionOperations": {
"type": "bool",
"defaultValue": true,
Expand Down Expand Up @@ -1041,6 +1048,21 @@
"vm_nic"
]
},
"vm_configurationAssignment": {
"condition": "[not(empty(parameters('maintenanceConfigurationResourceId')))]",
"type": "Microsoft.Maintenance/configurationAssignments",
"apiVersion": "2023-04-01",
"scope": "[format('Microsoft.Compute/virtualMachines/{0}', parameters('name'))]",
"name": "[format('{0}assignment', parameters('name'))]",
"location": "[parameters('location')]",
"properties": {
"maintenanceConfigurationId": "[parameters('maintenanceConfigurationResourceId')]",
"resourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('name'))]"
},
"dependsOn": [
"vm"
]
},
"vm_configurationProfileAssignment": {
"condition": "[not(empty(parameters('configurationProfile')))]",
"type": "Microsoft.Automanage/configurationProfileAssignments",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@description('Required. The name of the Virtual Network to create.')
param virtualNetworkName string

@description('Required. The name of the Maintenance Configuration to create.')
param maintenanceConfigurationName string

@description('Required. The name of the Application Security Group to create.')
param applicationSecurityGroupName string

Expand Down Expand Up @@ -54,6 +57,39 @@ resource virtualNetwork 'Microsoft.Network/virtualNetworks@2023-04-01' = {
}
}

resource maintenanceConfiguration 'Microsoft.Maintenance/maintenanceConfigurations@2023-10-01-preview' = {
name: maintenanceConfigurationName
location: location
properties: {
extensionProperties: {
InGuestPatchMode: 'User'
}
maintenanceScope: 'InGuestPatch'
maintenanceWindow: {
startDateTime: '2024-06-16 00:00'
duration: '03:55'
timeZone: 'W. Europe Standard Time'
recurEvery: '1Day'
}
visibility: 'Custom'
installPatches: {
rebootSetting: 'IfRequired'
windowsParameters: {
classificationsToInclude: [
'Critical'
'Security'
]
}
linuxParameters: {
classificationsToInclude: [
'Critical'
'Security'
]
}
}
}
}

resource applicationSecurityGroup 'Microsoft.Network/applicationSecurityGroups@2023-04-01' = {
name: applicationSecurityGroupName
location: location
Expand Down Expand Up @@ -275,7 +311,7 @@ resource storageUpload 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
properties: {
azPowerShellVersion: '9.0'
retentionInterval: 'P1D'
arguments: '-StorageAccountName "${storageAccount.name}" -ResourceGroupName "${resourceGroup().name}" -ContainerName "${storageAccount::blobService::container.name}" -FileName "${storageAccountCSEFileName}"'
arguments: '-StorageAccountName ${storageAccount.name} -ResourceGroupName ${resourceGroup().name} -ContainerName ${storageAccount::blobService::container.name} -FileName ${storageAccountCSEFileName}'
scriptContent: loadTextContent('../../../../../../utilities/e2e-template-assets/scripts/Set-BlobContent.ps1')
}
dependsOn: [
Expand All @@ -291,6 +327,9 @@ resource proximityPlacementGroup 'Microsoft.Compute/proximityPlacementGroups@202
@description('The resource ID of the created Virtual Network Subnet.')
output subnetResourceId string = virtualNetwork.properties.subnets[0].id

@description('The resource ID of the maintenance configuration.')
output maintenanceConfigurationResourceId string = maintenanceConfiguration.id

@description('The resource ID of the created Application Security Group.')
output applicationSecurityGroupResourceId string = applicationSecurityGroup.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module nestedDependencies 'dependencies.bicep' = {
params: {
location: resourceLocation
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
maintenanceConfigurationName: 'dep-${namePrefix}-mc-${serviceShort}'
applicationSecurityGroupName: 'dep-${namePrefix}-asg-${serviceShort}'
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
keyVaultName: 'dep-${namePrefix}-kv-${serviceShort}'
Expand Down Expand Up @@ -197,6 +198,8 @@ module testDeployment '../../../main.bicep' = [
]
enableAutomaticUpdates: true
patchMode: 'AutomaticByPlatform'
bypassPlatformSafetyChecksOnUserSchedule: true
maintenanceConfigurationResourceId: nestedDependencies.outputs.maintenanceConfigurationResourceId
encryptionAtHost: false
extensionAntiMalwareConfig: {
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
- Azure.ContainerApp.PublicAccess
# Azure Virtual Machine
- Azure.VM.AMA
- Azure.VM.MaintenanceConfig # Excluded as it requires user input
- Azure.VM.Standalone
# Azure App Service
- Azure.AppService.WebProbe # Supressed as the probe path is specific to the app
Expand Down

0 comments on commit a930335

Please sign in to comment.