Skip to content
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

[Modules] Add support for Virtual Machine Automatic VM Guest Patching #2429

Merged
merged 14 commits into from
Dec 22, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ module testDeployment '../../deploy.bicep' = {
}
}
]
enableAutomaticUpdates: true
patchMode: 'AutomaticByPlatform'
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId
diagnosticWorkspaceId: diagnosticDependencies.outputs.logAnalyticsWorkspaceResourceId
diagnosticEventHubAuthorizationRuleId: diagnosticDependencies.outputs.eventHubAuthorizationRuleId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ module testDeployment '../../deploy.bicep' = {
}
}
]
enableAutomaticUpdates: true
patchMode: 'AutomaticByPlatform'
diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId
diagnosticWorkspaceId: diagnosticDependencies.outputs.logAnalyticsWorkspaceResourceId
diagnosticEventHubAuthorizationRuleId: diagnosticDependencies.outputs.eventHubAuthorizationRuleId
Expand Down
27 changes: 26 additions & 1 deletion modules/Microsoft.Compute/virtualMachines/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,26 @@ param disablePasswordAuthentication bool = false
@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

@description('Optional. Indicates whether Automatic Updates is enabled for the Windows virtual machine. Default value is true. For virtual machine scale sets, this property can be updated and updates will take effect on OS reprovisioning.')
@description('Optional. Indicates whether Automatic Updates is enabled for the Windows virtual machine. Default value is true. When patchMode is set to Manual, this parameter must be set to false. For virtual machine scale sets, this property can be updated and updates will take effect on OS reprovisioning.')
param enableAutomaticUpdates bool = true

@description('Optional. VM guest patching orchestration mode. \'AutomaticByOS\' & \'Manual\' are for Windows only, \'ImageDefault\' for Linux only. Refer to \'https://learn.microsoft.com/en-us/azure/virtual-machines/automatic-vm-guest-patching\'')
@allowed([
'AutomaticByPlatform'
'AutomaticByOS'
'Manual'
'ImageDefault'
''
])
param patchMode string = ''

@description('Optional. VM guest patching assessment mode. Set it to \'AutomaticByPlatform\' to enable automatically check for updates every 24 hours.')
@allowed([
'AutomaticByPlatform'
'ImageDefault'
])
param patchAssessmentMode string = 'ImageDefault'

@description('Optional. Specifies the time zone of the virtual machine. e.g. \'Pacific Standard Time\'. Possible values can be `TimeZoneInfo.id` value from time zones returned by `TimeZoneInfo.GetSystemTimeZones`.')
param timeZone string = ''

Expand Down Expand Up @@ -305,11 +322,19 @@ var linuxConfiguration = {
publicKeys: publicKeysFormatted
}
provisionVMAgent: provisionVMAgent
patchSettings: (provisionVMAgent && (patchMode =~ 'AutomaticByPlatform' || patchMode =~ 'ImageDefault')) ? {
patchMode: patchMode
assessmentMode: patchAssessmentMode
} : null
}

var windowsConfiguration = {
provisionVMAgent: provisionVMAgent
enableAutomaticUpdates: enableAutomaticUpdates
patchSettings: (provisionVMAgent && (patchMode =~ 'AutomaticByPlatform' || patchMode =~ 'AutomaticByOS' || patchMode =~ 'Manual')) ? {
tyconsulting marked this conversation as resolved.
Show resolved Hide resolved
patchMode: patchMode
assessmentMode: patchAssessmentMode
} : null
timeZone: empty(timeZone) ? null : timeZone
additionalUnattendContent: empty(additionalUnattendContent) ? null : additionalUnattendContent
winRM: !empty(winRM) ? {
Expand Down
20 changes: 19 additions & 1 deletion modules/Microsoft.Compute/virtualMachines/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This module deploys one Virtual Machine with one or multiple NICs and optionally
| `diagnosticStorageAccountId` | string | `''` | | Resource ID of the diagnostic storage account. |
| `diagnosticWorkspaceId` | string | `''` | | Resource ID of the diagnostic log analytics workspace. |
| `disablePasswordAuthentication` | bool | `False` | | Specifies whether password authentication should be disabled. |
| `enableAutomaticUpdates` | bool | `True` | | Indicates whether Automatic Updates is enabled for the Windows virtual machine. Default value is true. For virtual machine scale sets, this property can be updated and updates will take effect on OS reprovisioning. |
| `enableAutomaticUpdates` | bool | `True` | | Indicates whether Automatic Updates is enabled for the Windows virtual machine. Default value is true. When patchMode is set to Manual, this parameter must be set to false. For virtual machine scale sets, this property can be updated and updates will take effect on OS reprovisioning. |
| `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via a Globally Unique Identifier (GUID). |
| `enableEvictionPolicy` | bool | `False` | | Specifies the eviction policy for the low priority virtual machine. Will result in 'Deallocate' eviction policy. |
| `encryptionAtHost` | bool | `True` | | This property can be used by user in the request to enable or disable the Host Encryption for the virtual machine. This will enable the encryption for all the disks including Resource/Temp disk at host itself. For security reasons, it is recommended to set encryptionAtHost to True. Restrictions: Cannot be enabled if Azure Disk Encryption (guest-VM encryption using bitlocker/DM-Crypt) is enabled on your VMs. |
Expand All @@ -86,6 +86,8 @@ This module deploys one Virtual Machine with one or multiple NICs and optionally
| `name` | string | `[take(toLower(uniqueString(resourceGroup().name)), 10)]` | | The name of the virtual machine to be created. You should use a unique prefix to reduce name collisions in Active Directory. If no value is provided, a 10 character long unique string will be generated based on the Resource Group's name. |
| `nicdiagnosticMetricsToEnable` | array | `[AllMetrics]` | `[AllMetrics]` | The name of metrics that will be streamed. |
| `nicDiagnosticSettingsName` | string | `[format('{0}-diagnosticSettings', parameters('name'))]` | | The name of the NIC diagnostic setting, if deployed. |
| `patchAssessmentMode` | string | `'ImageDefault'` | `[AutomaticByPlatform, ImageDefault]` | VM guest patching assessment mode. Set it to 'AutomaticByPlatform' to enable automatically check for updates every 24 hours. |
| `patchMode` | string | `''` | `['', AutomaticByOS, AutomaticByPlatform, ImageDefault, Manual]` | VM guest patching orchestration mode. 'AutomaticByOS' & 'Manual' are for Windows only, 'ImageDefault' for Linux only. Refer to 'https://learn.microsoft.com/en-us/azure/virtual-machines/automatic-vm-guest-patching' |
| `pipdiagnosticLogCategoriesToEnable` | array | `[allLogs]` | `[allLogs, DDoSMitigationFlowLogs, DDoSMitigationReports, DDoSProtectionNotifications]` | The name of logs that will be streamed. "allLogs" includes all possible logs for the resource. |
| `pipdiagnosticMetricsToEnable` | array | `[AllMetrics]` | `[AllMetrics]` | The name of metrics that will be streamed. |
| `pipDiagnosticSettingsName` | string | `[format('{0}-diagnosticSettings', parameters('name'))]` | | The name of the PIP diagnostic setting, if deployed. |
Expand Down Expand Up @@ -1137,6 +1139,7 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
diagnosticStorageAccountId: '<diagnosticStorageAccountId>'
diagnosticWorkspaceId: '<diagnosticWorkspaceId>'
disablePasswordAuthentication: true
enableAutomaticUpdates: true
enableDefaultTelemetry: '<enableDefaultTelemetry>'
encryptionAtHost: false
extensionAzureDiskEncryptionConfig: {
Expand Down Expand Up @@ -1180,6 +1183,7 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
lock: 'CanNotDelete'
monitoringWorkspaceId: '<monitoringWorkspaceId>'
name: '<<namePrefix>>cvmlincom'
patchMode: 'AutomaticByPlatform'
publicKeys: [
{
keyData: '<keyData>'
Expand Down Expand Up @@ -1342,6 +1346,9 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
"disablePasswordAuthentication": {
"value": true
},
"enableAutomaticUpdates": {
"value": true
},
"enableDefaultTelemetry": {
"value": "<enableDefaultTelemetry>"
},
Expand Down Expand Up @@ -1411,6 +1418,9 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
"name": {
"value": "<<namePrefix>>cvmlincom"
},
"patchMode": {
"value": "AutomaticByPlatform"
},
"publicKeys": {
"value": [
{
Expand Down Expand Up @@ -1826,6 +1836,7 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
diagnosticLogsRetentionInDays: 7
diagnosticStorageAccountId: '<diagnosticStorageAccountId>'
diagnosticWorkspaceId: '<diagnosticWorkspaceId>'
enableAutomaticUpdates: true
enableDefaultTelemetry: '<enableDefaultTelemetry>'
encryptionAtHost: false
extensionAntiMalwareConfig: {
Expand Down Expand Up @@ -1887,6 +1898,7 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
lock: 'CanNotDelete'
monitoringWorkspaceId: '<monitoringWorkspaceId>'
name: '<<namePrefix>>cvmwincom'
patchMode: 'AutomaticByPlatform'
proximityPlacementGroupResourceId: '<proximityPlacementGroupResourceId>'
roleAssignments: [
{
Expand Down Expand Up @@ -2044,6 +2056,9 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
"diagnosticWorkspaceId": {
"value": "<diagnosticWorkspaceId>"
},
"enableAutomaticUpdates": {
"value": true
},
"enableDefaultTelemetry": {
"value": "<enableDefaultTelemetry>"
},
Expand Down Expand Up @@ -2133,6 +2148,9 @@ module virtualMachines './Microsoft.Compute/virtualMachines/deploy.bicep' = {
"name": {
"value": "<<namePrefix>>cvmwincom"
},
"patchMode": {
"value": "AutomaticByPlatform"
},
"proximityPlacementGroupResourceId": {
"value": "<proximityPlacementGroupResourceId>"
},
Expand Down