Skip to content

Commit

Permalink
fix: various fixes on VM (Azure#3116)
Browse files Browse the repository at this point in the history
fixes:
- Azure#2843 
- error in readme fixed (missing dot in parameter description)
- enableHotpatch is disabled by default
- allowed types added to securityType

successfull run (except NVidia test due to MCPS restrictions):
[![avm.res.compute.virtual-machine](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg)](https://github.com/rahalan/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml)

---------

Co-authored-by: Alexander Sehr <[email protected]>
  • Loading branch information
rahalan and AlexanderSehr authored Aug 30, 2024
1 parent 8f64d2c commit 604beb8
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 81 deletions.
62 changes: 52 additions & 10 deletions avm/res/compute/virtual-machine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ This module deploys a Virtual Machine with one or multiple NICs and optionally o
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Automanage/configurationProfileAssignments` | [2022-05-04](https://learn.microsoft.com/en-us/azure/templates) |
| `Microsoft.Compute/virtualMachines` | [2023-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Compute/2023-09-01/virtualMachines) |
| `Microsoft.Compute/virtualMachines` | [2024-03-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Compute/2024-03-01/virtualMachines) |
| `Microsoft.Compute/virtualMachines/extensions` | [2022-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Compute/2022-11-01/virtualMachines/extensions) |
| `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/dataCollectionRuleAssociations` | [2023-03-11](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2023-03-11/dataCollectionRuleAssociations) |
| `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) |
Expand Down Expand Up @@ -565,8 +566,13 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
}
}
extensionMonitoringAgentConfig: {
dataCollectionRuleAssociations: [
{
dataCollectionRuleResourceId: '<dataCollectionRuleResourceId>'
name: 'SendMetricsToLAW'
}
]
enabled: true
monitoringWorkspaceResourceId: '<monitoringWorkspaceResourceId>'
tags: {
Environment: 'Non-Prod'
'hidden-title': 'This is visible in the resource name'
Expand Down Expand Up @@ -892,8 +898,13 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
},
"extensionMonitoringAgentConfig": {
"value": {
"dataCollectionRuleAssociations": [
{
"dataCollectionRuleResourceId": "<dataCollectionRuleResourceId>",
"name": "SendMetricsToLAW"
}
],
"enabled": true,
"monitoringWorkspaceResourceId": "<monitoringWorkspaceResourceId>",
"tags": {
"Environment": "Non-Prod",
"hidden-title": "This is visible in the resource name",
Expand Down Expand Up @@ -1196,6 +1207,12 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
}
}
extensionMonitoringAgentConfig: {
dataCollectionRuleAssociations: [
{
dataCollectionRuleResourceId: '<dataCollectionRuleResourceId>'
name: 'SendMetricsToLAW'
}
]
enabled: true
tags: {
Environment: 'Non-Prod'
Expand Down Expand Up @@ -1518,6 +1535,12 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
},
"extensionMonitoringAgentConfig": {
"value": {
"dataCollectionRuleAssociations": [
{
"dataCollectionRuleResourceId": "<dataCollectionRuleResourceId>",
"name": "SendMetricsToLAW"
}
],
"enabled": true,
"tags": {
"Environment": "Non-Prod",
Expand Down Expand Up @@ -2332,8 +2355,13 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
}
}
extensionMonitoringAgentConfig: {
dataCollectionRuleAssociations: [
{
dataCollectionRuleResourceId: '<dataCollectionRuleResourceId>'
name: 'SendMetricsToLAW'
}
]
enabled: true
monitoringWorkspaceResourceId: '<monitoringWorkspaceResourceId>'
tags: {
Environment: 'Non-Prod'
'hidden-title': 'This is visible in the resource name'
Expand Down Expand Up @@ -2693,8 +2721,13 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
},
"extensionMonitoringAgentConfig": {
"value": {
"dataCollectionRuleAssociations": [
{
"dataCollectionRuleResourceId": "<dataCollectionRuleResourceId>",
"name": "SendMetricsToLAW"
}
],
"enabled": true,
"monitoringWorkspaceResourceId": "<monitoringWorkspaceResourceId>",
"tags": {
"Environment": "Non-Prod",
"hidden-title": "This is visible in the resource name",
Expand Down Expand Up @@ -3220,7 +3253,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
| [`disablePasswordAuthentication`](#parameter-disablepasswordauthentication) | bool | Specifies whether password authentication should be disabled. |
| [`enableAutomaticUpdates`](#parameter-enableautomaticupdates) | bool | 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. |
| [`enableEvictionPolicy`](#parameter-enableevictionpolicy) | bool | Specifies the eviction policy for the low priority virtual machine. Will result in 'Deallocate' eviction policy. |
| [`enableHotpatching`](#parameter-enablehotpatching) | bool | Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform' |
| [`enableHotpatching`](#parameter-enablehotpatching) | bool | Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'. |
| [`enableTelemetry`](#parameter-enabletelemetry) | bool | Enable/Disable usage telemetry for module. |
| [`encryptionAtHost`](#parameter-encryptionathost) | bool | 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. |
| [`extensionAadJoinConfig`](#parameter-extensionaadjoinconfig) | object | The configuration for the [AAD Join] extension. Must at least contain the ["enabled": true] property to be executed. To enroll in Intune, add the setting mdmId: "0000000a-0000-0000-c000-000000000000". |
Expand Down Expand Up @@ -3257,7 +3290,7 @@ module virtualMachine 'br/public:avm/res/compute/virtual-machine:<version>' = {
| [`roleAssignments`](#parameter-roleassignments) | array | Array of role assignments to create. |
| [`sasTokenValidityLength`](#parameter-sastokenvaliditylength) | string | SAS token validity length to use to download files from storage accounts. Usage: 'PT8H' - valid for 8 hours; 'P5D' - valid for 5 days; 'P1Y' - valid for 1 year. When not provided, the SAS token will be valid for 8 hours. |
| [`secureBootEnabled`](#parameter-securebootenabled) | bool | Specifies whether secure boot should be enabled on the virtual machine. This parameter is part of the UefiSettings. SecurityType should be set to TrustedLaunch to enable UefiSettings. |
| [`securityType`](#parameter-securitytype) | string | Specifies the SecurityType of the virtual machine. It is set as TrustedLaunch to enable UefiSettings. |
| [`securityType`](#parameter-securitytype) | string | Specifies the SecurityType of the virtual machine. It has to be set to any specified value to enable UefiSettings. The default behavior is: UefiSettings will not be enabled unless this property is set. |
| [`tags`](#parameter-tags) | object | Tags of the resource. |
| [`timeZone`](#parameter-timezone) | string | 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`. |
| [`ultraSSDEnabled`](#parameter-ultrassdenabled) | bool | The flag that enables or disables a capability to have one or more managed data disks with UltraSSD_LRS storage account type on the VM or VMSS. Managed disks with storage account type UltraSSD_LRS can be added to a virtual machine or virtual machine scale set only if this property is enabled. |
Expand Down Expand Up @@ -3753,11 +3786,11 @@ Specifies the eviction policy for the low priority virtual machine. Will result

### Parameter: `enableHotpatching`

Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'
Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.

- Required: No
- Type: bool
- Default: `True`
- Default: `False`

### Parameter: `enableTelemetry`

Expand Down Expand Up @@ -3921,6 +3954,7 @@ The configuration for the [Monitoring Agent] extension. Must at least contain th
- Default:
```Bicep
{
dataCollectionRuleAssociations: []
enabled: false
}
```
Expand Down Expand Up @@ -4286,11 +4320,19 @@ Specifies whether secure boot should be enabled on the virtual machine. This par

### Parameter: `securityType`

Specifies the SecurityType of the virtual machine. It is set as TrustedLaunch to enable UefiSettings.
Specifies the SecurityType of the virtual machine. It has to be set to any specified value to enable UefiSettings. The default behavior is: UefiSettings will not be enabled unless this property is set.

- Required: No
- Type: string
- Default: `''`
- Allowed:
```Bicep
[
''
'ConfidentialVM'
'TrustedLaunch'
]
```

### Parameter: `tags`

Expand Down
61 changes: 23 additions & 38 deletions avm/res/compute/virtual-machine/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ param vmSize string
@description('Optional. 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.')
param encryptionAtHost bool = true

@description('Optional. Specifies the SecurityType of the virtual machine. It is set as TrustedLaunch to enable UefiSettings.')
@description('Optional. Specifies the SecurityType of the virtual machine. It has to be set to any specified value to enable UefiSettings. The default behavior is: UefiSettings will not be enabled unless this property is set.')
@allowed([
''
'ConfidentialVM'
'TrustedLaunch'
])
param securityType string = ''

@description('Optional. Specifies whether secure boot should be enabled on the virtual machine. This parameter is part of the UefiSettings. SecurityType should be set to TrustedLaunch to enable UefiSettings.')
Expand Down Expand Up @@ -159,6 +164,7 @@ param extensionAntiMalwareConfig object = {
@description('Optional. The configuration for the [Monitoring Agent] extension. Must at least contain the ["enabled": true] property to be executed.')
param extensionMonitoringAgentConfig object = {
enabled: false
dataCollectionRuleAssociations: []
}

@description('Optional. The configuration for the [Dependency Agent] extension. Must at least contain the ["enabled": true] property to be executed.')
Expand Down Expand Up @@ -281,8 +287,8 @@ param rebootSetting string = 'IfRequired'
])
param patchAssessmentMode string = 'ImageDefault'

@description('Optional. Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the \'provisionVMAgent\' must be set to true and \'patchMode\' must be set to \'AutomaticByPlatform\'')
param enableHotpatching bool = true
@description('Optional. Enables customers to patch their Azure VMs without requiring a reboot. For enableHotpatching, the \'provisionVMAgent\' must be set to true and \'patchMode\' must be set to \'AutomaticByPlatform\'.')
param enableHotpatching bool = false

@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 @@ -497,7 +503,7 @@ module vm_nic 'modules/nic-configuration.bicep' = [
}
]

resource vm 'Microsoft.Compute/virtualMachines@2023-09-01' = {
resource vm 'Microsoft.Compute/virtualMachines@2024-03-01' = {
name: name
location: location
identity: identity
Expand Down Expand Up @@ -753,29 +759,6 @@ module vm_microsoftAntiMalwareExtension 'extension/main.bicep' = if (extensionAn
]
}

resource vm_logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = if (!empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId)) {
name: last(split(
(!empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '')
? extensionMonitoringAgentConfig.monitoringWorkspaceId
: 'law'),
'/'
))!
scope: az.resourceGroup(
split(
(!empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '')
? extensionMonitoringAgentConfig.monitoringWorkspaceId
: '//'),
'/'
)[2],
split(
(!empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '')
? extensionMonitoringAgentConfig.monitoringWorkspaceId
: '////'),
'/'
)[4]
)
}

module vm_azureMonitorAgentExtension 'extension/main.bicep' = if (extensionMonitoringAgentConfig.enabled) {
name: '${uniqueString(deployment().name, location)}-VM-AzureMonitorAgent'
params: {
Expand All @@ -787,25 +770,27 @@ module vm_azureMonitorAgentExtension 'extension/main.bicep' = if (extensionMonit
typeHandlerVersion: extensionMonitoringAgentConfig.?typeHandlerVersion ?? (osType == 'Windows' ? '1.22' : '1.29')
autoUpgradeMinorVersion: extensionMonitoringAgentConfig.?autoUpgradeMinorVersion ?? true
enableAutomaticUpgrade: extensionMonitoringAgentConfig.?enableAutomaticUpgrade ?? false
settings: {
workspaceId: !empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '')
? vm_logAnalyticsWorkspace.properties.customerId
: ''
GCS_AUTO_CONFIG: osType == 'Linux' ? true : null
}
supressFailures: extensionMonitoringAgentConfig.?supressFailures ?? false
tags: extensionMonitoringAgentConfig.?tags ?? tags
protectedSettings: {
workspaceKey: !empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '')
? vm_logAnalyticsWorkspace.listKeys().primarySharedKey
: ''
}
}
dependsOn: [
vm_microsoftAntiMalwareExtension
]
}

resource vm_dataCollectionRuleAssociations 'Microsoft.Insights/dataCollectionRuleAssociations@2023-03-11' = [
for (dataCollectionRuleAssociation, index) in extensionMonitoringAgentConfig.dataCollectionRuleAssociations: if (extensionMonitoringAgentConfig.enabled) {
name: dataCollectionRuleAssociation.name
scope: vm
properties: {
dataCollectionRuleId: dataCollectionRuleAssociation.dataCollectionRuleResourceId
}
dependsOn: [
vm_azureMonitorAgentExtension
]
}
]

module vm_dependencyAgentExtension 'extension/main.bicep' = if (extensionDependencyAgentConfig.enabled) {
name: '${uniqueString(deployment().name, location)}-VM-DependencyAgent'
params: {
Expand Down
Loading

0 comments on commit 604beb8

Please sign in to comment.