Bylaw

Gallery › Monitoring › Azure built-in policies

Configure Linux machines to run Azure Monitor Agent and associate them to a Data Collection Rule

Converted Initiative Version 3.2.0

Monitor and secure your Linux virtual machines, virtual machine scale sets, and Arc machines by deploying the Azure Monitor Agent extension and associating the machines with a specified Data Collection Rule. Deployment will occur on machines with supported OS images (or machines matching the provided list of images) in supported regions.

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

Azure Policy JSONAzureMonitor_LinuxPlatform_EnableDCR.json · 125 lines
{
  "properties": {
    "displayName": "Configure Linux machines to run Azure Monitor Agent and associate them to a Data Collection Rule",
    "policyType": "BuiltIn",
    "description": "Monitor and secure your Linux virtual machines, virtual machine scale sets, and Arc machines by deploying the Azure Monitor Agent extension and associating the machines with a specified Data Collection Rule. Deployment will occur on machines with supported OS images (or machines matching the provided list of images) in supported regions.",
    "metadata": {
      "version": "3.2.0",
      "category": "Monitoring"
    },
    "version": "3.2.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy."
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "scopeToSupportedImages": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Scope Policy to Azure Monitor Agent-Supported Operating Systems",
          "description": "If set to true, the policy will apply only to machines with supported operating systems. Otherwise, the policy will apply to all machines in the assignment scope. For supported operating systems, see https://aka.ms/AMAOverview."
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      },
      "listOfLinuxImageIdToInclude": {
        "type": "Array",
        "metadata": {
          "displayName": "Additional Virtual Machine Images",
          "description": "List of virtual machine images that have supported Linux OS to add to scope. Example values: '/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'"
        },
        "defaultValue": []
      },
      "dcrResourceId": {
        "type": "String",
        "metadata": {
          "displayName": "Data Collection Rule Resource Id",
          "description": "Resource Id of the Data Collection Rule that the virtual machines in scope should be associated with."
        }
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/a4034bc6-ae50-406d-bf76-50f4ee5a7811",
        "definitionVersion": "3.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitorAgentLinuxVM",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfLinuxImageIdToInclude": {
            "value": "[parameters('listOfLinuxImageIdToInclude')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/56a3e4f8-649b-4fac-887e-5564d11e8d3a",
        "definitionVersion": "3.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitorAgentLinuxVMSS",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfLinuxImageIdToInclude": {
            "value": "[parameters('listOfLinuxImageIdToInclude')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/845857af-0333-4c5d-bbbc-6076697da122",
        "definitionVersion": "2.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitorAgentLinuxHybridVM",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2ea82cdd-f2e8-4500-af75-67a2e084ca74",
        "definitionVersion": "6.*.*",
        "policyDefinitionReferenceId": "associateDataCollectionRuleLinux",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfLinuxImageIdToInclude": {
            "value": "[parameters('listOfLinuxImageIdToInclude')]"
          },
          "dcrResourceId": {
            "value": "[parameters('dcrResourceId')]"
          },
          "resourceType": {
            "value": "Microsoft.Insights/dataCollectionRules"
          }
        }
      }
    ],
    "versions": [
      "3.2.0",
      "3.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/118f04da-0375-44d1-84e3-0fd9e1849403",
  "name": "118f04da-0375-44d1-84e3-0fd9e1849403"
}
Bylaw118f04da-0375-44d1-84e3-0fd9e1849403.bylaw.ps1 · 80 lines
# Converted from AzureMonitor_LinuxPlatform_EnableDCR.json by ConvertTo-Bylaw.
Initiative '118f04da-0375-44d1-84e3-0fd9e1849403' {

    Properties @{
        DisplayName   = 'Configure Linux machines to run Azure Monitor Agent and associate them to a Data Collection Rule'
        Description   = 'Monitor and secure your Linux virtual machines, virtual machine scale sets, and Arc machines by deploying the Azure Monitor Agent extension and associating the machines with a specified Data Collection Rule. Deployment will occur on machines with supported OS images (or machines matching the provided list of images) in supported regions.'
        Version       = '3.2.0'
        Category      = 'Monitoring'
        PolicyVersion = '3.2.0'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }
    Parameter ScopeToSupportedImages @{
        Type          = 'Boolean'
        AllowedValues = @($true, $false)
        Default       = $true
        DisplayName   = 'Scope Policy to Azure Monitor Agent-Supported Operating Systems'
        Description   = 'If set to true, the policy will apply only to machines with supported operating systems. Otherwise, the policy will apply to all machines in the assignment scope. For supported operating systems, see https://aka.ms/AMAOverview.'
    }
    Parameter ListOfLinuxImageIdToInclude @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Additional Virtual Machine Images'
        Description = 'List of virtual machine images that have supported Linux OS to add to scope. Example values: ''/subscriptions/<subscriptionId>/resourceGroups/YourResourceGroup/providers/Microsoft.Compute/images/ContosoStdImage'''
    }
    Parameter DcrResourceId @{
        Type        = 'String'
        DisplayName = 'Data Collection Rule Resource Id'
        Description = 'Resource Id of the Data Collection Rule that the virtual machines in scope should be associated with.'
    }

    PolicyDefinition @{
        Id          = 'a4034bc6-ae50-406d-bf76-50f4ee5a7811'
        ReferenceId = 'deployAzureMonitorAgentLinuxVM'
        Version     = '3.*.*'
        Parameters  = [ordered]@{
            effect                      = (Param Effect)
            scopeToSupportedImages      = (Param ScopeToSupportedImages)
            listOfLinuxImageIdToInclude = (Param ListOfLinuxImageIdToInclude)
        }
    }

    PolicyDefinition @{
        Id          = '56a3e4f8-649b-4fac-887e-5564d11e8d3a'
        ReferenceId = 'deployAzureMonitorAgentLinuxVMSS'
        Version     = '3.*.*'
        Parameters  = [ordered]@{
            effect                      = (Param Effect)
            scopeToSupportedImages      = (Param ScopeToSupportedImages)
            listOfLinuxImageIdToInclude = (Param ListOfLinuxImageIdToInclude)
        }
    }

    PolicyDefinition @{
        Id          = '845857af-0333-4c5d-bbbc-6076697da122'
        ReferenceId = 'deployAzureMonitorAgentLinuxHybridVM'
        Version     = '2.*.*'
        Parameters  = @{
            effect = (Param Effect)
        }
    }

    PolicyDefinition @{
        Id          = '2ea82cdd-f2e8-4500-af75-67a2e084ca74'
        ReferenceId = 'associateDataCollectionRuleLinux'
        Version     = '6.*.*'
        Parameters  = [ordered]@{
            effect                      = (Param Effect)
            scopeToSupportedImages      = (Param ScopeToSupportedImages)
            listOfLinuxImageIdToInclude = (Param ListOfLinuxImageIdToInclude)
            dcrResourceId               = (Param DcrResourceId)
            resourceType                = 'Microsoft.Insights/dataCollectionRules'
        }
    }
}

Members (4)

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