Skip to content

Commit

Permalink
feat: Restored features of CARML AMA PR (#784)
Browse files Browse the repository at this point in the history
## 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 <56914614+eriqua@users.noreply.github.com>
  • Loading branch information
AlexanderSehr and eriqua authored Jan 15, 2024
1 parent f6b569f commit fa5b073
Show file tree
Hide file tree
Showing 16 changed files with 2,952 additions and 911 deletions.
3,046 changes: 2,191 additions & 855 deletions avm/res/compute/virtual-machine/README.md

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions avm/res/compute/virtual-machine/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ metadata name = 'Virtual Machines'
metadata description = 'This module deploys a Virtual Machine with one or multiple NICs and optionally one or multiple public IPs.'
metadata owner = 'Azure/module-maintainers'

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

Expand Down Expand Up @@ -515,23 +514,30 @@ module vm_microsoftAntiMalwareExtension 'extension/main.bicep' = if (extensionAn
}
}

// resource vm_logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = if (!empty(monitoringWorkspaceId)) {
// name: last(split((!empty(monitoringWorkspaceId) ? monitoringWorkspaceId : 'law'), '/'))!
// scope: az.resourceGroup(split((!empty(monitoringWorkspaceId) ? monitoringWorkspaceId : '//'), '/')[2], split((!empty(monitoringWorkspaceId) ? monitoringWorkspaceId : '////'), '/')[4])
// }
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_azureMonitoringAgentExtension 'extension/main.bicep' = if (extensionMonitoringAgentConfig.enabled) {
name: '${uniqueString(deployment().name, location)}-VM-AzureMonitoringAgent'
module vm_azureMonitorAgentExtension 'extension/main.bicep' = if (extensionMonitoringAgentConfig.enabled) {
name: '${uniqueString(deployment().name, location)}-VM-AzureMonitorAgent'
params: {
virtualMachineName: vm.name
name: 'AzureMonitorAgent'
location: location
publisher: 'Microsoft.Azure.Monitor'
type: osType == 'Windows' ? 'AzureMonitorWindowsAgent' : 'AzureMonitorLinuxAgent'
typeHandlerVersion: contains(extensionMonitoringAgentConfig, 'typeHandlerVersion') ? extensionMonitoringAgentConfig.typeHandlerVersion : (osType == 'Windows' ? '1.0' : '1.21')
autoUpgradeMinorVersion: contains(extensionMonitoringAgentConfig, 'autoUpgradeMinorVersion') ? extensionMonitoringAgentConfig.autoUpgradeMinorVersion : true
enableAutomaticUpgrade: contains(extensionMonitoringAgentConfig, 'enableAutomaticUpgrade') ? extensionMonitoringAgentConfig.enableAutomaticUpgrade : true
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
}
tags: extensionMonitoringAgentConfig.?tags ?? tags
protectedSettings: {
workspaceKey: !empty(extensionMonitoringAgentConfig.?monitoringWorkspaceId ?? '') ? vm_logAnalyticsWorkspace.listKeys().primarySharedKey : ''
}
}
}

Expand Down Expand Up @@ -621,7 +627,7 @@ module vm_azureDiskEncryptionExtension 'extension/main.bicep' = if (extensionAzu
}
dependsOn: [
vm_customScriptExtension
vm_azureMonitoringAgentExtension
vm_azureMonitorAgentExtension
]
}

Expand All @@ -640,7 +646,7 @@ module vm_backup 'modules/protected-item.bicep' = if (!empty(backupVaultName)) {
dependsOn: [
vm_aadJoinExtension
vm_domainJoinExtension
vm_azureMonitoringAgentExtension
vm_azureMonitorAgentExtension
vm_microsoftAntiMalwareExtension
vm_networkWatcherAgentExtension
vm_dependencyAgentExtension
Expand Down
45 changes: 36 additions & 9 deletions 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.24.24.22086",
"templateHash": "7458372846706074174"
"templateHash": "6402533243232998196"
},
"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 @@ -902,6 +902,15 @@
"vm"
]
},
"vm_logAnalyticsWorkspace": {
"condition": "[not(empty(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId')))]",
"existing": true,
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2021-06-01",
"subscriptionId": "[split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '//'), '/')[2]]",
"resourceGroup": "[split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, '////'), '/')[4]]",
"name": "[last(split(if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), parameters('extensionMonitoringAgentConfig').monitoringWorkspaceId, 'law'), '/'))]"
},
"vm_lock": {
"condition": "[and(not(empty(coalesce(parameters('lock'), createObject()))), not(equals(tryGet(parameters('lock'), 'kind'), 'None')))]",
"type": "Microsoft.Authorization/locks",
Expand Down Expand Up @@ -3003,11 +3012,11 @@
"vm"
]
},
"vm_azureMonitoringAgentExtension": {
"vm_azureMonitorAgentExtension": {
"condition": "[parameters('extensionMonitoringAgentConfig').enabled]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "[format('{0}-VM-AzureMonitoringAgent', uniqueString(deployment().name, parameters('location')))]",
"name": "[format('{0}-VM-AzureMonitorAgent', uniqueString(deployment().name, parameters('location')))]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
Expand All @@ -3027,11 +3036,28 @@
"value": "Microsoft.Azure.Monitor"
},
"type": "[if(equals(parameters('osType'), 'Windows'), createObject('value', 'AzureMonitorWindowsAgent'), createObject('value', 'AzureMonitorLinuxAgent'))]",
"typeHandlerVersion": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'typeHandlerVersion'), createObject('value', parameters('extensionMonitoringAgentConfig').typeHandlerVersion), if(equals(parameters('osType'), 'Windows'), createObject('value', '1.0'), createObject('value', '1.21')))]",
"autoUpgradeMinorVersion": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'autoUpgradeMinorVersion'), createObject('value', parameters('extensionMonitoringAgentConfig').autoUpgradeMinorVersion), createObject('value', true()))]",
"enableAutomaticUpgrade": "[if(contains(parameters('extensionMonitoringAgentConfig'), 'enableAutomaticUpgrade'), createObject('value', parameters('extensionMonitoringAgentConfig').enableAutomaticUpgrade), createObject('value', true()))]",
"typeHandlerVersion": {
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'typeHandlerVersion'), if(equals(parameters('osType'), 'Windows'), '1.22', '1.29'))]"
},
"autoUpgradeMinorVersion": {
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'autoUpgradeMinorVersion'), true())]"
},
"enableAutomaticUpgrade": {
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'enableAutomaticUpgrade'), false())]"
},
"settings": {
"value": {
"workspaceId": "[if(not(empty(coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'monitoringWorkspaceId'), ''))), reference('vm_logAnalyticsWorkspace').customerId, '')]",
"GCS_AUTO_CONFIG": "[if(equals(parameters('osType'), 'Linux'), true(), null())]"
}
},
"tags": {
"value": "[coalesce(tryGet(parameters('extensionMonitoringAgentConfig'), 'tags'), parameters('tags'))]"
},
"protectedSettings": {
"value": {
"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, '')]"
}
}
},
"template": {
Expand Down Expand Up @@ -3196,7 +3222,8 @@
}
},
"dependsOn": [
"vm"
"vm",
"vm_logAnalyticsWorkspace"
]
},
"vm_dependencyAgentExtension": {
Expand Down Expand Up @@ -4198,7 +4225,7 @@
},
"dependsOn": [
"vm",
"vm_azureMonitoringAgentExtension",
"vm_azureMonitorAgentExtension",
"vm_customScriptExtension"
]
},
Expand Down Expand Up @@ -4347,7 +4374,7 @@
"dependsOn": [
"vm",
"vm_aadJoinExtension",
"vm_azureMonitoringAgentExtension",
"vm_azureMonitorAgentExtension",
"vm_customScriptExtension",
"vm_dependencyAgentExtension",
"vm_desiredStateConfigurationExtension",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ param serviceShort string = 'cvmlinatmg'
@description('Optional. A token to inject into the name of each resource.')
param namePrefix string = '#_namePrefix_#'

#disable-next-line no-hardcoded-location // Just a value to avoid ongoing capacity challenges
var tempLocation = 'northeurope'

// ============ //
// Dependencies //
// ============ //
Expand All @@ -35,7 +38,7 @@ module nestedDependencies 'dependencies.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
params: {
location: location
location: tempLocation
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
sshDeploymentScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
sshKeyName: 'dep-${namePrefix}-ssh-${serviceShort}'
Expand All @@ -57,7 +60,7 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
scope: resourceGroup
name: '${uniqueString(deployment().name, location)}-test-${serviceShort}-${iteration}'
params: {
location: location
location: tempLocation
name: '${namePrefix}${serviceShort}'
adminUsername: 'localAdminUser'
imageReference: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
targetScope = 'subscription'

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

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

#disable-next-line no-hardcoded-location // Just a value to avoid ongoing capacity challenges
var tempLocation = 'northeurope'

// ============ //
// Dependencies //
// ============ //
Expand All @@ -35,7 +38,7 @@ module nestedDependencies 'dependencies.bicep' = {
scope: resourceGroup
name: '${uniqueString(deployment().name, location)}-nestedDependencies'
params: {
location: location
location: tempLocation
virtualNetworkName: 'dep-${namePrefix}-vnet-${serviceShort}'
managedIdentityName: 'dep-${namePrefix}-msi-${serviceShort}'
sshDeploymentScriptName: 'dep-${namePrefix}-ds-${serviceShort}'
Expand All @@ -57,7 +60,7 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
scope: resourceGroup
name: '${uniqueString(deployment().name, location)}-test-${serviceShort}-${iteration}'
params: {
location: location
location: tempLocation
name: '${namePrefix}${serviceShort}'
adminUsername: 'localAdminUser'
imageReference: {
Expand Down
Loading

0 comments on commit fa5b073

Please sign in to comment.