Skip to content

Commit

Permalink
add maintenance Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rahalan committed Jun 16, 2024
1 parent e81ccdd commit 0193ff5
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 3 deletions.
52 changes: 51 additions & 1 deletion 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 @@ -231,6 +232,10 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
name: 'ipconfig01'
pipConfiguration: {
name: 'pip-01'
tags: {
Environment: 'Non-Prod'
Role: 'DeploymentValidation'
}
}
subnetResourceId: '<subnetResourceId>'
}
Expand All @@ -249,8 +254,11 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
vmSize: 'Standard_DS2_v2'
zone: 0
// Non-required parameters
bypassPlatformSafetyChecksOnUserSchedule: true
disablePasswordAuthentication: true
location: '<location>'
maintenanceConfigurationId: '<maintenanceConfigurationId>'
patchMode: 'AutomaticByPlatform'
publicKeys: [
{
keyData: '<keyData>'
Expand Down Expand Up @@ -295,7 +303,11 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
{
"name": "ipconfig01",
"pipConfiguration": {
"name": "pip-01"
"name": "pip-01",
"tags": {
"Environment": "Non-Prod",
"Role": "DeploymentValidation"
}
},
"subnetResourceId": "<subnetResourceId>"
}
Expand Down Expand Up @@ -323,12 +335,21 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
"value": 0
},
// Non-required parameters
"bypassPlatformSafetyChecksOnUserSchedule": {
"value": true
},
"disablePasswordAuthentication": {
"value": true
},
"location": {
"value": "<location>"
},
"maintenanceConfigurationId": {
"value": "<maintenanceConfigurationId>"
},
"patchMode": {
"value": "AutomaticByPlatform"
},
"publicKeys": {
"value": [
{
Expand Down Expand Up @@ -1039,6 +1060,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 +1188,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
kind: 'CanNotDelete'
name: 'myCustomLockName'
}
maintenanceConfigurationId: '<maintenanceConfigurationId>'
managedIdentities: {
systemAssigned: true
userAssignedResourceIds: [
Expand Down Expand Up @@ -1334,6 +1357,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 +1517,9 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
"name": "myCustomLockName"
}
},
"maintenanceConfigurationId": {
"value": "<maintenanceConfigurationId>"
},
"managedIdentities": {
"value": {
"systemAssigned": true,
Expand Down Expand Up @@ -1583,7 +1612,10 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
zone: 0
// Non-required parameters
adminPassword: '<adminPassword>'
bypassPlatformSafetyChecksOnUserSchedule: true
location: '<location>'
maintenanceConfigurationId: '<maintenanceConfigurationId>'
patchMode: 'AutomaticByPlatform'
}
}
```
Expand Down Expand Up @@ -1650,8 +1682,17 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
"adminPassword": {
"value": "<adminPassword>"
},
"bypassPlatformSafetyChecksOnUserSchedule": {
"value": true
},
"location": {
"value": "<location>"
},
"maintenanceConfigurationId": {
"value": "<maintenanceConfigurationId>"
},
"patchMode": {
"value": "AutomaticByPlatform"
}
}
}
Expand Down Expand Up @@ -3137,6 +3178,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. |
| [`maintenanceConfigurationId`](#parameter-maintenanceconfigurationid) | 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 +3961,14 @@ Specify the name of lock.
- Required: No
- Type: string

### Parameter: `maintenanceConfigurationId`

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
11 changes: 11 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 maintenanceConfigurationId 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,14 @@ resource vm 'Microsoft.Compute/virtualMachines@2023-09-01' = {
]
}

resource vm_configurationAssignment 'Microsoft.Maintenance/configurationAssignments@2023-04-01' = if (!empty(maintenanceConfigurationId)) {
name: 'default'
properties: {
maintenanceConfigurationId: maintenanceConfigurationId
}
scope: vm
}

resource vm_configurationProfileAssignment 'Microsoft.Automanage/configurationProfileAssignments@2022-05-04' = if (!empty(configurationProfile)) {
name: 'default'
properties: {
Expand Down
22 changes: 21 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": "8464205482993315248"
},
"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."
}
},
"maintenanceConfigurationId": {
"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,19 @@
"vm_nic"
]
},
"vm_configurationAssignment": {
"condition": "[not(empty(parameters('maintenanceConfigurationId')))]",
"type": "Microsoft.Maintenance/configurationAssignments",
"apiVersion": "2023-04-01",
"scope": "[format('Microsoft.Compute/virtualMachines/{0}', parameters('name'))]",
"name": "default",
"properties": {
"maintenanceConfigurationId": "[parameters('maintenanceConfigurationId')]"
},
"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 Managed Identity to create.')
param managedIdentityName string

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

resource maintenanceConfiguration 'Microsoft.Maintenance/maintenanceConfigurations@2023-10-01-preview' = {
name: maintenanceConfigurationName
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'
]
}
}
// configurationType: 'Regular'
}
}

resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: managedIdentityName
location: location
Expand Down Expand Up @@ -85,5 +121,8 @@ resource sshKey 'Microsoft.Compute/sshPublicKeys@2022-03-01' = {
@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 Public Key of the created SSH Key.')
output SSHKeyPublicKey string = sshKey.properties.publicKey
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module nestedDependencies 'dependencies.bicep' = {
params: {
location: resourceLocation
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
maintenanceConfigurationName: 'dep-${namePrefix}-mc-${serviceShort}'
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
sshDeploymentScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
sshKeyName: 'dep-${namePrefix}-ssh-${serviceShort}'
Expand Down Expand Up @@ -76,6 +77,10 @@ module testDeployment '../../../main.bicep' = [
subnetResourceId: nestedDependencies.outputs.subnetResourceId
pipConfiguration: {
name: 'pip-01'
tags: {
Environment: 'Non-Prod'
Role: 'DeploymentValidation'
}
}
}
]
Expand All @@ -92,6 +97,9 @@ module testDeployment '../../../main.bicep' = [
osType: 'Linux'
vmSize: 'Standard_DS2_v2'
disablePasswordAuthentication: true
patchMode: 'AutomaticByPlatform'
bypassPlatformSafetyChecksOnUserSchedule: true
maintenanceConfigurationId: nestedDependencies.outputs.maintenanceConfigurationResourceId
publicKeys: [
{
keyData: nestedDependencies.outputs.SSHKeyPublicKey
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
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'
]
}
}
// configurationType: 'Regular'
}
}

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
maintenanceConfigurationId: nestedDependencies.outputs.maintenanceConfigurationResourceId
encryptionAtHost: false
extensionAntiMalwareConfig: {
enabled: true
Expand Down
Loading

0 comments on commit 0193ff5

Please sign in to comment.