Gallery › Security Center › Azure built-in policies
Configure SQL Virtual Machines to automatically install Azure Monitor Agent
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.6.0
Automate the deployment of Azure Monitor Agent extension on your Windows SQL Virtual Machines. Learn more: https://aka.ms/AMAOverview.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONMDC_DfSQL_DeployWindowsAMA_VM.json · 176 lines
{
"properties": {
"displayName": "Configure SQL Virtual Machines to automatically install Azure Monitor Agent",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Automate the deployment of Azure Monitor Agent extension on your Windows SQL Virtual Machines. Learn more: https://aka.ms/AMAOverview.",
"version": "1.6.0",
"metadata": {
"version": "1.6.0",
"category": "Security Center"
},
"parameters": {
"bringYourOwnUserAssignedManagedIdentity": {
"type": "Boolean",
"metadata": {
"displayName": "Bring Your Own User-Assigned Identity",
"description": "Enable this to use your pre-created user-assigned managed identity. The pre-created identity MUST exist otherwise the policy deployment will fail. If enabled, ensure that the user-assigned managed identity resource ID parameter matches the pre-created user-assigned managed identity resource ID. If not enabled, the policy will create per subscription, per resource user-assigned managed identities in a new resource group named 'Built-In-Identity-RG'."
},
"allowedValues": [
true,
false
],
"defaultValue": false
},
"userAssignedIdentityResourceId": {
"type": "String",
"metadata": {
"displayName": "User-Assigned Managed Identity Resource ID",
"description": "The resource ID of the pre-created user-assigned managed identity. This parameter is only used when the Centralized User-Assigned Managed Identity parameter is true."
},
"defaultValue": ""
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.SqlVirtualMachine/SqlVirtualMachines"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Compute/virtualMachines/extensions",
"evaluationDelay": "AfterProvisioning",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"
],
"name": "[concat(last(split(field('Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId'), '/')), '/?')]",
"existenceCondition": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"equals": "SqlIaaSAgentLinux"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.SqlServer.Management"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"equals": "AzureMonitorWindowsAgent"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.Azure.Monitor"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
"in": [
"Succeeded",
"Provisioning succeeded"
]
}
]
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"vmName": {
"value": "[last(split(field('Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId'), '/'))]"
},
"location": {
"value": "[field('location')]"
},
"userAssignedManagedIdentity": {
"value": "[if(parameters('bringYourOwnUserAssignedManagedIdentity'), parameters('userAssignedIdentityResourceId'), concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-', field('location')))]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"location": {
"type": "string"
},
"userAssignedManagedIdentity": {
"type": "string"
}
},
"variables": {
"extensionName": "AzureMonitorWindowsAgent",
"extensionPublisher": "Microsoft.Azure.Monitor",
"extensionType": "AzureMonitorWindowsAgent",
"extensionTypeHandlerVersion": "1.2"
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/', variables('extensionName'))]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"location": "[parameters('location')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
},
"apiVersion": "2023-03-01",
"properties": {
"publisher": "[variables('extensionPublisher')]",
"type": "[variables('extensionType')]",
"typeHandlerVersion": "[variables('extensionTypeHandlerVersion')]",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"settings": {
"authentication": {
"managedIdentity": {
"identifier-name": "mi_res_id",
"identifier-value": "[parameters('userAssignedManagedIdentity')]"
}
}
}
}
}
]
}
}
}
}
}
},
"versions": [
"1.6.0",
"1.5.0",
"1.4.0",
"1.3.0",
"1.2.2",
"1.2.1-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/f91991d1-5383-4c95-8ee5-5ac423dd8bb1",
"name": "f91991d1-5383-4c95-8ee5-5ac423dd8bb1"
}Bylawf91991d1-5383-4c95-8ee5-5ac423dd8bb1.bylaw.ps1 · 54 lines
# Converted from MDC_DfSQL_DeployWindowsAMA_VM.json by ConvertTo-Bylaw.
Policy 'f91991d1-5383-4c95-8ee5-5ac423dd8bb1' {
Properties @{
DisplayName = 'Configure SQL Virtual Machines to automatically install Azure Monitor Agent'
Description = 'Automate the deployment of Azure Monitor Agent extension on your Windows SQL Virtual Machines. Learn more: https://aka.ms/AMAOverview.'
Version = '1.6.0'
Category = 'Security Center'
PolicyVersion = '1.6.0'
Mode = 'Indexed'
}
Parameter BringYourOwnUserAssignedManagedIdentity @{
Type = 'Boolean'
AllowedValues = @($true, $false)
Default = $false
DisplayName = 'Bring Your Own User-Assigned Identity'
Description = 'Enable this to use your pre-created user-assigned managed identity. The pre-created identity MUST exist otherwise the policy deployment will fail. If enabled, ensure that the user-assigned managed identity resource ID parameter matches the pre-created user-assigned managed identity resource ID. If not enabled, the policy will create per subscription, per resource user-assigned managed identities in a new resource group named ''Built-In-Identity-RG''.'
}
Parameter UserAssignedIdentityResourceId @{
Default = ''
DisplayName = 'User-Assigned Managed Identity Resource ID'
Description = 'The resource ID of the pre-created user-assigned managed identity. This parameter is only used when the Centralized User-Assigned Managed Identity parameter is true.'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.SqlVirtualMachine/SqlVirtualMachines'
DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Virtual Machine Contributor' -Name (Arm '[concat(last(split(field(''Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId''), ''/'')), ''/?'')]') -EvaluationDelay AfterProvisioning -Effect (Param Effect) {
Require 'type, publisher and provisioningState are as required' {
AnyOf {
AllOf {
Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'SqlIaaSAgentLinux'
Field publisher | Must -Be 'Microsoft.SqlServer.Management'
}
AllOf {
Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'AzureMonitorWindowsAgent'
Field publisher | Must -Be 'Microsoft.Azure.Monitor'
Field provisioningState | Must -BeIn @('Succeeded', 'Provisioning succeeded')
}
}
}
Deployment -TemplateFile './templates/f91991d1-5383-4c95-8ee5-5ac423dd8bb1.json' -Parameters ([ordered]@{
vmName = (Arm '[last(split(field(''Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId''), ''/''))]')
location = (Arm '[field(''location'')]')
userAssignedManagedIdentity = (Arm '[if(parameters(''bringYourOwnUserAssignedManagedIdentity''), parameters(''userAssignedIdentityResourceId''), concat(''/subscriptions/'', subscription().subscriptionId, ''/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-'', field(''location'')))]')
})
}
}Its deployment templates are written beside it:
templates/f91991d1-5383-4c95-8ee5-5ac423dd8bb1.json
Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_DeployWindowsAMA_VM.json in Azure/azure-policy, under the MIT licence.
Bylaw