Bylaw

Gallery › Monitoring › Azure built-in policies

[Deprecated]: Enable Azure Monitor for VMs with Azure Monitoring Agent(AMA)

Converted Initiative Version 1.2.2-preview Deprecated

Enable Azure Monitor for the virtual machines (VMs) with AMA. Takes Log Analytics workspace as parameter and asks for an option to enable Processes and Dependencies.

ConvertTo-Bylaw converted this initiative, and proved that the file compiles back to the same definition.

Azure Policy JSONAzureMonitor_VM_AMA.json · 243 lines
{
  "properties": {
    "displayName": "[Deprecated]: Enable Azure Monitor for VMs with Azure Monitoring Agent(AMA)",
    "policyType": "BuiltIn",
    "description": "Enable Azure Monitor for the virtual machines (VMs) with AMA. Takes Log Analytics workspace as parameter and asks for an option to enable Processes and Dependencies.",
    "metadata": {
      "version": "1.2.2-preview",
      "category": "Monitoring",
      "deprecated": true
    },
    "version": "1.2.2-preview",
    "parameters": {
      "logAnalyticsWorkspace": {
        "type": "String",
        "metadata": {
          "displayName": "Log Analytics workspace",
          "description": "Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant 'Log Analytics Contributor' permissions (or similar) to the policy assignment's principal ID.",
          "strongType": "omsWorkspace"
        }
      },
      "dataCollectionRuleName": {
        "type": "String",
        "metadata": {
          "displayName": "Name of the Data Collection Rule(DCR)",
          "description": "This is the name of the AMA-VMI Data Collection Rule(DCR)"
        },
        "defaultValue": "ama-vmi-default"
      },
      "enableProcessesAndDependencies": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Enable Processes and Dependencies",
          "description": "This is the flag for enabling processes and dependencies data collection in VMInsights"
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": false
      },
      "bringYourOwnUserAssignedManagedIdentity": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Bring Your Own User-Assigned Managed Identity",
          "description": "If set to true, Azure Monitor Agent will use the user-assigned managed identity specified via the 'User-Assigned Managed Identity ...' parameters for authentication. Otherwise, Azure Monitor Agent will use the user-assigned managed identity /subscriptions/<subscription-id>/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-<location> for authentication."
        },
        "allowedValues": [
          false,
          true
        ]
      },
      "userAssignedManagedIdentityName": {
        "type": "String",
        "metadata": {
          "displayName": "User-Assigned Managed Identity Name",
          "description": "The name of the user-assigned managed identity which Azure Monitor Agent will use for authentication when 'Bring Your Own User-Assigned Managed Identity' is set to true."
        },
        "defaultValue": ""
      },
      "userAssignedManagedIdentityResourceGroup": {
        "type": "String",
        "metadata": {
          "displayName": "User-Assigned Managed Identity Resource Group",
          "description": "The resource group of the user-assigned managed identity which Azure Monitor Agent will use for authentication when 'Bring Your Own User-Assigned Managed Identity' is set to true."
        },
        "defaultValue": ""
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect for all constituent policies",
          "description": "Enable or disable the execution of each of the constituent policies in the initiative."
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "listOfImageIdToInclude_windows": {
        "type": "Array",
        "defaultValue": [],
        "metadata": {
          "displayName": "Optional: List of VM images that have supported Windows OS to add to scope",
          "description": "Example value: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
        }
      },
      "listOfImageIdToInclude_linux": {
        "type": "Array",
        "defaultValue": [],
        "metadata": {
          "displayName": "Optional: List of VM images that have supported Linux OS to add to scope",
          "description": "Example value: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
        }
      },
      "scopeToSupportedImages": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Scope Policy to Dependency Agent-Supported Operating Systems",
          "description": "If set to true, the policy will apply only to virtual machines with supported operating systems. Otherwise, the policy will apply to all virtual machine resources in the assignment scope. For supported operating systems, see https://learn.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-dependency-agent-maintenance"
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionReferenceId": "AddUserAssignedManagedIdentity_VM",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/d367bd60-64ca-4364-98ea-276775bddd94",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "userAssignedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "identityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/ae8a10e6-19d6-44a3-a02d-a2bdfc707742",
        "definitionVersion": "3.*.*",
        "policyDefinitionReferenceId": "DeployAzureMonitoringAgentLinuxVMWithUAI",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "userAssignedManagedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "userAssignedManagedIdentityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          },
          "listOfLinuxImageIdToInclude": {
            "value": "[parameters('listOfImageIdToInclude_linux')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/637125fd-7c39-4b94-bb0a-d331faf333a9",
        "definitionVersion": "1.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitoringAgentWindowsVMWithUAI",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "listOfWindowsImageIdToInclude": {
            "value": "[parameters('listOfImageIdToInclude_windows')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "userAssignedManagedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "userAssignedManagedIdentityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "DependencyAgentExtension_Windows_VM_AMA_Deploy",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/89ca9cc7-25cd-4d53-97ba-445ca7a1f222",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "listOfImageIdToInclude": {
            "value": "[parameters('listOfImageIdToInclude_windows')]"
          },
          "enableProcessesAndDependencies": {
            "value": "[parameters('enableProcessesAndDependencies')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "DependencyAgentExtension_Linux_VM_AMA_Deploy",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/d55b81e1-984f-4a96-acab-fae204e3ca7f",
        "definitionVersion": "3.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "listOfImageIdToInclude": {
            "value": "[parameters('listOfImageIdToInclude_linux')]"
          },
          "enableProcessesAndDependencies": {
            "value": "[parameters('enableProcessesAndDependencies')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          }
        }
      },
      {
        "policyDefinitionReferenceId": "VMInsightsDCR_DCRA_VM_Deploy",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/a0f27bdc-5b15-4810-b81d-7c4df9df1a37",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "workspaceResourceId": {
            "value": "[parameters('logAnalyticsWorkspace')]"
          },
          "userGivenDcrName": {
            "value": "[parameters('dataCollectionRuleName')]"
          },
          "enableProcessesAndDependencies": {
            "value": "[parameters('enableProcessesAndDependencies')]"
          }
        }
      }
    ],
    "versions": [
      "1.2.2-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/9dffaf29-5905-4145-883c-957eb442c226",
  "name": "9dffaf29-5905-4145-883c-957eb442c226"
}
Bylaw9dffaf29-5905-4145-883c-957eb442c226.bylaw.ps1 · 148 lines
# Converted from AzureMonitor_VM_AMA.json by ConvertTo-Bylaw.
Initiative '9dffaf29-5905-4145-883c-957eb442c226' {

    Properties @{
        DisplayName   = '[Deprecated]: Enable Azure Monitor for VMs with Azure Monitoring Agent(AMA)'
        Description   = 'Enable Azure Monitor for the virtual machines (VMs) with AMA. Takes Log Analytics workspace as parameter and asks for an option to enable Processes and Dependencies.'
        Version       = '1.2.2-preview'
        Category      = 'Monitoring'
        Deprecated    = $true
        PolicyVersion = '1.2.2-preview'
    }

    Parameter LogAnalyticsWorkspace @{
        Type        = 'String'
        DisplayName = 'Log Analytics workspace'
        Description = 'Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant ''Log Analytics Contributor'' permissions (or similar) to the policy assignment''s principal ID.'
        Metadata    = [ordered]@{ strongType = 'omsWorkspace' }
    }
    Parameter DataCollectionRuleName @{
        Default     = 'ama-vmi-default'
        DisplayName = 'Name of the Data Collection Rule(DCR)'
        Description = 'This is the name of the AMA-VMI Data Collection Rule(DCR)'
    }
    Parameter EnableProcessesAndDependencies @{
        Type          = 'Boolean'
        AllowedValues = @($true, $false)
        Default       = $false
        DisplayName   = 'Enable Processes and Dependencies'
        Description   = 'This is the flag for enabling processes and dependencies data collection in VMInsights'
    }
    Parameter BringYourOwnUserAssignedManagedIdentity @{
        Type          = 'Boolean'
        AllowedValues = @($false, $true)
        DisplayName   = 'Bring Your Own User-Assigned Managed Identity'
        Description   = 'If set to true, Azure Monitor Agent will use the user-assigned managed identity specified via the ''User-Assigned Managed Identity ...'' parameters for authentication. Otherwise, Azure Monitor Agent will use the user-assigned managed identity /subscriptions/<subscription-id>/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-<location> for authentication.'
    }
    Parameter UserAssignedManagedIdentityName @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Name'
        Description = 'The name of the user-assigned managed identity which Azure Monitor Agent will use for authentication when ''Bring Your Own User-Assigned Managed Identity'' is set to true.'
    }
    Parameter UserAssignedManagedIdentityResourceGroup @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Resource Group'
        Description = 'The resource group of the user-assigned managed identity which Azure Monitor Agent will use for authentication when ''Bring Your Own User-Assigned Managed Identity'' is set to true.'
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect for all constituent policies'
        Description   = 'Enable or disable the execution of each of the constituent policies in the initiative.'
    }
    Parameter ListOfImageIdToInclude_windows @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Optional: List of VM images that have supported Windows OS to add to scope'
        Description = 'Example value: ''/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'''
    }
    Parameter ListOfImageIdToInclude_linux @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Optional: List of VM images that have supported Linux OS to add to scope'
        Description = 'Example value: ''/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'''
    }
    Parameter ScopeToSupportedImages @{
        Type          = 'Boolean'
        AllowedValues = @($true, $false)
        Default       = $true
        DisplayName   = 'Scope Policy to Dependency Agent-Supported Operating Systems'
        Description   = 'If set to true, the policy will apply only to virtual machines with supported operating systems. Otherwise, the policy will apply to all virtual machine resources in the assignment scope. For supported operating systems, see https://learn.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-dependency-agent-maintenance'
    }

    PolicyDefinition @{
        Id          = 'd367bd60-64ca-4364-98ea-276775bddd94'
        ReferenceId = 'AddUserAssignedManagedIdentity_VM'
        Version     = '1.*.*-preview'
        Parameters  = [ordered]@{
            effect                                  = (Param Effect)
            bringYourOwnUserAssignedManagedIdentity = (Param BringYourOwnUserAssignedManagedIdentity)
            userAssignedIdentityName                = (Param UserAssignedManagedIdentityName)
            identityResourceGroup                   = (Param UserAssignedManagedIdentityResourceGroup)
        }
    }

    PolicyDefinition @{
        Id          = 'ae8a10e6-19d6-44a3-a02d-a2bdfc707742'
        ReferenceId = 'DeployAzureMonitoringAgentLinuxVMWithUAI'
        Version     = '3.*.*'
        Parameters  = [ordered]@{
            effect                                   = (Param Effect)
            bringYourOwnUserAssignedManagedIdentity  = (Param BringYourOwnUserAssignedManagedIdentity)
            userAssignedManagedIdentityName          = (Param UserAssignedManagedIdentityName)
            userAssignedManagedIdentityResourceGroup = (Param UserAssignedManagedIdentityResourceGroup)
            listOfLinuxImageIdToInclude              = (Param ListOfImageIdToInclude_linux)
            scopeToSupportedImages                   = (Param ScopeToSupportedImages)
        }
    }

    PolicyDefinition @{
        Id          = '637125fd-7c39-4b94-bb0a-d331faf333a9'
        ReferenceId = 'deployAzureMonitoringAgentWindowsVMWithUAI'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            effect                                   = (Param Effect)
            listOfWindowsImageIdToInclude            = (Param ListOfImageIdToInclude_windows)
            bringYourOwnUserAssignedManagedIdentity  = (Param BringYourOwnUserAssignedManagedIdentity)
            userAssignedManagedIdentityName          = (Param UserAssignedManagedIdentityName)
            userAssignedManagedIdentityResourceGroup = (Param UserAssignedManagedIdentityResourceGroup)
            scopeToSupportedImages                   = (Param ScopeToSupportedImages)
        }
    }

    PolicyDefinition @{
        Id          = '89ca9cc7-25cd-4d53-97ba-445ca7a1f222'
        ReferenceId = 'DependencyAgentExtension_Windows_VM_AMA_Deploy'
        Version     = '1.*.*-preview'
        Parameters  = [ordered]@{
            effect                         = (Param Effect)
            listOfImageIdToInclude         = (Param ListOfImageIdToInclude_windows)
            enableProcessesAndDependencies = (Param EnableProcessesAndDependencies)
            scopeToSupportedImages         = (Param ScopeToSupportedImages)
        }
    }

    PolicyDefinition @{
        Id          = 'd55b81e1-984f-4a96-acab-fae204e3ca7f'
        ReferenceId = 'DependencyAgentExtension_Linux_VM_AMA_Deploy'
        Version     = '3.*.*-preview'
        Parameters  = [ordered]@{
            effect                         = (Param Effect)
            listOfImageIdToInclude         = (Param ListOfImageIdToInclude_linux)
            enableProcessesAndDependencies = (Param EnableProcessesAndDependencies)
            scopeToSupportedImages         = (Param ScopeToSupportedImages)
        }
    }

    PolicyDefinition @{
        Id          = 'a0f27bdc-5b15-4810-b81d-7c4df9df1a37'
        ReferenceId = 'VMInsightsDCR_DCRA_VM_Deploy'
        Version     = '1.*.*-preview'
        Parameters  = [ordered]@{
            effect                         = (Param Effect)
            workspaceResourceId            = (Param LogAnalyticsWorkspace)
            userGivenDcrName               = (Param DataCollectionRuleName)
            enableProcessesAndDependencies = (Param EnableProcessesAndDependencies)
        }
    }
}

Members (6)

Source: built-in-policies/policySetDefinitions/Monitoring/AzureMonitor_VM_AMA.json in Azure/azure-policy, under the MIT licence.