Skip to content

Commit fa5b073

Browse files
feat: Restored features of CARML AMA PR (#784)
## Description - Retored the functionality introduced by PR Azure/ResourceModules#3938 - Updated Set-AVMModule utility to be able to handle modules that don't use plane test names like `max` but instead e.g., `<prefix>.max` - Small update to docs and regeneration of files - Shifted deployment location as encountering capacity issues in WestEurope - Added a warning supression for Network/Connection that was added for the same reason | Pipeline | | - | | [![avm.res.compute.virtual-machine](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg?branch=users%2Falsehr%2FvmUpdate20240110&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml) | --------- Co-authored-by: Erika Gressi <[email protected]>
1 parent f6b569f commit fa5b073

File tree

16 files changed

+2952
-911
lines changed

16 files changed

+2952
-911
lines changed

avm/res/compute/virtual-machine/README.md

Lines changed: 2191 additions & 855 deletions
Large diffs are not rendered by default.

avm/res/compute/virtual-machine/main.bicep

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ metadata name = 'Virtual Machines'
22
metadata description = 'This module deploys a Virtual Machine with one or multiple NICs and optionally one or multiple public IPs.'
33
metadata owner = 'Azure/module-maintainers'
44

5-
// Main resource
65
@description('Required. The name of the virtual machine to be created. You should use a unique prefix to reduce name collisions in Active Directory.')
76
param name string
87

@@ -515,23 +514,30 @@ module vm_microsoftAntiMalwareExtension 'extension/main.bicep' = if (extensionAn
515514
}
516515
}
517516

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

523-
module vm_azureMonitoringAgentExtension 'extension/main.bicep' = if (extensionMonitoringAgentConfig.enabled) {
524-
name: '${uniqueString(deployment().name, location)}-VM-AzureMonitoringAgent'
522+
module vm_azureMonitorAgentExtension 'extension/main.bicep' = if (extensionMonitoringAgentConfig.enabled) {
523+
name: '${uniqueString(deployment().name, location)}-VM-AzureMonitorAgent'
525524
params: {
526525
virtualMachineName: vm.name
527526
name: 'AzureMonitorAgent'
528527
location: location
529528
publisher: 'Microsoft.Azure.Monitor'
530529
type: osType == 'Windows' ? 'AzureMonitorWindowsAgent' : 'AzureMonitorLinuxAgent'
531-
typeHandlerVersion: contains(extensionMonitoringAgentConfig, 'typeHandlerVersion') ? extensionMonitoringAgentConfig.typeHandlerVersion : (osType == 'Windows' ? '1.0' : '1.21')
532-
autoUpgradeMinorVersion: contains(extensionMonitoringAgentConfig, 'autoUpgradeMinorVersion') ? extensionMonitoringAgentConfig.autoUpgradeMinorVersion : true
533-
enableAutomaticUpgrade: contains(extensionMonitoringAgentConfig, 'enableAutomaticUpgrade') ? extensionMonitoringAgentConfig.enableAutomaticUpgrade : true
530+
typeHandlerVersion: extensionMonitoringAgentConfig.?typeHandlerVersion ?? (osType == 'Windows' ? '1.22' : '1.29')
531+
autoUpgradeMinorVersion: extensionMonitoringAgentConfig.?autoUpgradeMinorVersion ?? true
532+
enableAutomaticUpgrade: extensionMonitoringAgentConfig.?enableAutomaticUpgrade ?? false
533+
settings: {
534+
workspaceId: !empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '') ? vm_logAnalyticsWorkspace.properties.customerId : ''
535+
GCS_AUTO_CONFIG: osType == 'Linux' ? true : null
536+
}
534537
tags: extensionMonitoringAgentConfig.?tags ?? tags
538+
protectedSettings: {
539+
workspaceKey: !empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '') ? vm_logAnalyticsWorkspace.listKeys().primarySharedKey : ''
540+
}
535541
}
536542
}
537543

@@ -621,7 +627,7 @@ module vm_azureDiskEncryptionExtension 'extension/main.bicep' = if (extensionAzu
621627
}
622628
dependsOn: [
623629
vm_customScriptExtension
624-
vm_azureMonitoringAgentExtension
630+
vm_azureMonitorAgentExtension
625631
]
626632
}
627633

@@ -640,7 +646,7 @@ module vm_backup 'modules/protected-item.bicep' = if (!empty(backupVaultName)) {
640646
dependsOn: [
641647
vm_aadJoinExtension
642648
vm_domainJoinExtension
643-
vm_azureMonitoringAgentExtension
649+
vm_azureMonitorAgentExtension
644650
vm_microsoftAntiMalwareExtension
645651
vm_networkWatcherAgentExtension
646652
vm_dependencyAgentExtension

avm/res/compute/virtual-machine/main.json

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"_generator": {
77
"name": "bicep",
88
"version": "0.24.24.22086",
9-
"templateHash": "7458372846706074174"
9+
"templateHash": "6402533243232998196"
1010
},
1111
"name": "Virtual Machines",
1212
"description": "This module deploys a Virtual Machine with one or multiple NICs and optionally one or multiple public IPs.",
@@ -902,6 +902,15 @@
902902
"vm"
903903
]
904904
},
905+
"vm_logAnalyticsWorkspace": {
906+
"condition": "[not(empty(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId')))]",
907+
"existing": true,
908+
"type": "Microsoft.OperationalInsights/workspaces",
909+
"apiVersion": "2021-06-01",
910+
"subscriptionId": "[split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '//'), '/')[2]]",
911+
"resourceGroup": "[split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '////'), '/')[4]]",
912+
"name": "[last(split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, 'law'), '/'))]"
913+
},
905914
"vm_lock": {
906915
"condition": "[and(not(empty(coalesce(parameters('lock'), createObject()))), not(equals(tryGet(parameters('lock'), 'kind'), 'None')))]",
907916
"type": "Microsoft.Authorization/locks",
@@ -3003,11 +3012,11 @@
30033012
"vm"
30043013
]
30053014
},
3006-
"vm_azureMonitoringAgentExtension": {
3015+
"vm_azureMonitorAgentExtension": {
30073016
"condition": "[parameters('extensionMonitoringAgentConfig').enabled]",
30083017
"type": "Microsoft.Resources/deployments",
30093018
"apiVersion": "2022-09-01",
3010-
"name": "[format('{0}-VM-AzureMonitoringAgent', uniqueString(deployment().name, parameters('location')))]",
3019+
"name": "[format('{0}-VM-AzureMonitorAgent', uniqueString(deployment().name, parameters('location')))]",
30113020
"properties": {
30123021
"expressionEvaluationOptions": {
30133022
"scope": "inner"
@@ -3027,11 +3036,28 @@
30273036
"value": "Microsoft.Azure.Monitor"
30283037
},
30293038
"type": "[if(equals(parameters('osType'), 'Windows'), createObject('value', 'AzureMonitorWindowsAgent'), createObject('value', 'AzureMonitorLinuxAgent'))]",
3030-
"typeHandlerVersion": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'typeHandlerVersion'), createObject('value', parameters('extensionMonitoringAgentConfig').typeHandlerVersion), if(equals(parameters('osType'), 'Windows'), createObject('value', '1.0'), createObject('value', '1.21')))]",
3031-
"autoUpgradeMinorVersion": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'autoUpgradeMinorVersion'), createObject('value', parameters('extensionMonitoringAgentConfig').autoUpgradeMinorVersion), createObject('value', true()))]",
3032-
"enableAutomaticUpgrade": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'enableAutomaticUpgrade'), createObject('value', parameters('extensionMonitoringAgentConfig').enableAutomaticUpgrade), createObject('value', true()))]",
3039+
"typeHandlerVersion": {
3040+
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'typeHandlerVersion'), if(equals(parameters('osType'), 'Windows'), '1.22', '1.29'))]"
3041+
},
3042+
"autoUpgradeMinorVersion": {
3043+
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'autoUpgradeMinorVersion'), true())]"
3044+
},
3045+
"enableAutomaticUpgrade": {
3046+
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'enableAutomaticUpgrade'), false())]"
3047+
},
3048+
"settings": {
3049+
"value": {
3050+
"workspaceId": "[if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), reference('vm_logAnalyticsWorkspace').customerId, '')]",
3051+
"GCS_AUTO_CONFIG": "[if(equals(parameters('osType'), 'Linux'), true(), null())]"
3052+
}
3053+
},
30333054
"tags": {
30343055
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'tags'), parameters('tags'))]"
3056+
},
3057+
"protectedSettings": {
3058+
"value": {
3059+
"workspaceKey": "[if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), listKeys(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '//'), '/')[2], split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '////'), '/')[4]), 'Microsoft.OperationalInsights/workspaces', last(split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, 'law'), '/'))), '2021-06-01').primarySharedKey, '')]"
3060+
}
30353061
}
30363062
},
30373063
"template": {
@@ -3196,7 +3222,8 @@
31963222
}
31973223
},
31983224
"dependsOn": [
3199-
"vm"
3225+
"vm",
3226+
"vm_logAnalyticsWorkspace"
32003227
]
32013228
},
32023229
"vm_dependencyAgentExtension": {
@@ -4198,7 +4225,7 @@
41984225
},
41994226
"dependsOn": [
42004227
"vm",
4201-
"vm_azureMonitoringAgentExtension",
4228+
"vm_azureMonitorAgentExtension",
42024229
"vm_customScriptExtension"
42034230
]
42044231
},
@@ -4347,7 +4374,7 @@
43474374
"dependsOn": [
43484375
"vm",
43494376
"vm_aadJoinExtension",
4350-
"vm_azureMonitoringAgentExtension",
4377+
"vm_azureMonitorAgentExtension",
43514378
"vm_customScriptExtension",
43524379
"vm_dependencyAgentExtension",
43534380
"vm_desiredStateConfigurationExtension",

avm/res/compute/virtual-machine/tests/e2e/atmg/main.test.bicep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ param serviceShort string = 'cvmlinatmg'
2020
@description('Optional. A token to inject into the name of each resource.')
2121
param namePrefix string = '#_namePrefix_#'
2222

23+
#disable-next-line no-hardcoded-location // Just a value to avoid ongoing capacity challenges
24+
var tempLocation = 'northeurope'
25+
2326
// ============ //
2427
// Dependencies //
2528
// ============ //
@@ -35,7 +38,7 @@ module nestedDependencies 'dependencies.bicep' = {
3538
scope: resourceGroup
3639
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
3740
params: {
38-
location: location
41+
location: tempLocation
3942
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
4043
sshDeploymentScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
4144
sshKeyName: 'dep-${namePrefix}-ssh-${serviceShort}'
@@ -57,7 +60,7 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
5760
scope: resourceGroup
5861
name: '${uniqueString(deployment().name, location)}-test-${serviceShort}-${iteration}'
5962
params: {
60-
location: location
63+
location: tempLocation
6164
name: '${namePrefix}${serviceShort}'
6265
adminUsername: 'localAdminUser'
6366
imageReference: {

avm/res/compute/virtual-machine/tests/e2e/linux.defaults/main.test.bicep

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
targetScope = 'subscription'
22

3-
metadata name = 'Using only defaults'
3+
metadata name = 'Using only defaults for Linux'
44
metadata description = 'This instance deploys the module with the minimum set of required parameters.'
55

66
// ========== //
@@ -20,6 +20,9 @@ param serviceShort string = 'cvmlinmin'
2020
@description('Optional. A token to inject into the name of each resource.')
2121
param namePrefix string = '#_namePrefix_#'
2222

23+
#disable-next-line no-hardcoded-location // Just a value to avoid ongoing capacity challenges
24+
var tempLocation = 'northeurope'
25+
2326
// ============ //
2427
// Dependencies //
2528
// ============ //
@@ -35,7 +38,7 @@ module nestedDependencies 'dependencies.bicep' = {
3538
scope: resourceGroup
3639
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
3740
params: {
38-
location: location
41+
location: tempLocation
3942
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
4043
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
4144
sshDeploymentScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
@@ -57,7 +60,7 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
5760
scope: resourceGroup
5861
name: '${uniqueString(deployment().name, location)}-test-${serviceShort}-${iteration}'
5962
params: {
60-
location: location
63+
location: tempLocation
6164
name: '${namePrefix}${serviceShort}'
6265
adminUsername: 'localAdminUser'
6366
imageReference: {

0 commit comments

Comments
 (0)