Bylaw

Gallery › Monitoring › Azure built-in policies

Configure Linux Arc-enabled machines to run Azure Monitor Agent

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 2.4.0

Automate the deployment of Azure Monitor Agent extension on your Linux Arc-enabled machines for collecting telemetry data from the guest OS. This policy will install the extension if the region is supported. Learn more: https://aka.ms/AMAOverview.

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

Azure Policy JSONAzureMonitor_Agent_Linux_HybridVM_DINE.json · 178 lines
{
  "properties": {
    "displayName": "Configure Linux Arc-enabled machines to run Azure Monitor Agent",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Automate the deployment of Azure Monitor Agent extension on your Linux Arc-enabled machines for collecting telemetry data from the guest OS. This policy will install the extension if the region is supported. Learn more: https://aka.ms/AMAOverview.",
    "metadata": {
      "version": "2.4.0",
      "category": "Monitoring"
    },
    "version": "2.4.0",
    "parameters": {
      "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.HybridCompute/machines"
          },
          {
            "field": "Microsoft.HybridCompute/machines/osName",
            "equals": "linux"
          },
          {
            "field": "location",
            "in": [
              "australiacentral",
              "australiacentral2",
              "australiaeast",
              "australiasoutheast",
              "brazilsouth",
              "brazilsoutheast",
              "canadacentral",
              "canadaeast",
              "centralindia",
              "centralus",
              "centraluseuap",
              "eastasia",
              "eastus",
              "eastus2",
              "eastus2euap",
              "francecentral",
              "francesouth",
              "germanynorth",
              "germanywestcentral",
              "israelcentral",
              "italynorth",
              "japaneast",
              "japanwest",
              "jioindiacentral",
              "jioindiawest",
              "koreacentral",
              "koreasouth",
              "malaysiasouth",
              "mexicocentral",
              "northcentralus",
              "northeurope",
              "norwayeast",
              "norwaywest",
              "polandcentral",
              "qatarcentral",
              "southafricanorth",
              "southafricawest",
              "southcentralus",
              "southeastasia",
              "southindia",
              "spaincentral",
              "swedencentral",
              "swedensouth",
              "switzerlandnorth",
              "switzerlandwest",
              "taiwannorth",
              "taiwannorthwest",
              "uaecentral",
              "uaenorth",
              "uksouth",
              "ukwest",
              "westcentralus",
              "westeurope",
              "westindia",
              "westus",
              "westus2",
              "westus3"
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.HybridCompute/machines/extensions",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/cd570a14-e51a-42ad-bac8-bafd67325302"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.HybridCompute/machines/extensions/type",
                "equals": "AzureMonitorLinuxAgent"
              },
              {
                "field": "Microsoft.HybridCompute/machines/extensions/publisher",
                "equals": "Microsoft.Azure.Monitor"
              },
              {
                "field": "Microsoft.HybridCompute/machines/extensions/provisioningState",
                "equals": "Succeeded"
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "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"
                  }
                },
                "variables": {
                  "extensionName": "AzureMonitorLinuxAgent",
                  "extensionPublisher": "Microsoft.Azure.Monitor",
                  "extensionType": "AzureMonitorLinuxAgent"
                },
                "resources": [
                  {
                    "name": "[concat(parameters('vmName'), '/', variables('extensionName'))]",
                    "type": "Microsoft.HybridCompute/machines/extensions",
                    "location": "[parameters('location')]",
                    "apiVersion": "2021-05-20",
                    "properties": {
                      "publisher": "[variables('extensionPublisher')]",
                      "type": "[variables('extensionType')]",
                      "autoUpgradeMinorVersion": true,
                      "enableAutomaticUpgrade": true
                    }
                  }
                ]
              },
              "parameters": {
                "vmName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "2.4.0",
      "2.3.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/845857af-0333-4c5d-bbbc-6076697da122",
  "name": "845857af-0333-4c5d-bbbc-6076697da122"
}
Bylaw845857af-0333-4c5d-bbbc-6076697da122.bylaw.ps1 · 42 lines
# Converted from AzureMonitor_Agent_Linux_HybridVM_DINE.json by ConvertTo-Bylaw.
Policy '845857af-0333-4c5d-bbbc-6076697da122' {

    Properties @{
        DisplayName   = 'Configure Linux Arc-enabled machines to run Azure Monitor Agent'
        Description   = 'Automate the deployment of Azure Monitor Agent extension on your Linux Arc-enabled machines for collecting telemetry data from the guest OS. This policy will install the extension if the region is supported. Learn more: https://aka.ms/AMAOverview.'
        Version       = '2.4.0'
        Category      = 'Monitoring'
        PolicyVersion = '2.4.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }

    Resource 'Microsoft.HybridCompute/machines' {

        When {
            Field osName | Must -Be 'linux'
        }

        Require 'location is not one of 57 values' {
            Field location | Must -Not -BeIn @('australiacentral', 'australiacentral2', 'australiaeast', 'australiasoutheast', 'brazilsouth', 'brazilsoutheast', 'canadacentral', 'canadaeast', 'centralindia', 'centralus', 'centraluseuap', 'eastasia', 'eastus', 'eastus2', 'eastus2euap', 'francecentral', 'francesouth', 'germanynorth', 'germanywestcentral', 'israelcentral', 'italynorth', 'japaneast', 'japanwest', 'jioindiacentral', 'jioindiawest', 'koreacentral', 'koreasouth', 'malaysiasouth', 'mexicocentral', 'northcentralus', 'northeurope', 'norwayeast', 'norwaywest', 'polandcentral', 'qatarcentral', 'southafricanorth', 'southafricawest', 'southcentralus', 'southeastasia', 'southindia', 'spaincentral', 'swedencentral', 'swedensouth', 'switzerlandnorth', 'switzerlandwest', 'taiwannorth', 'taiwannorthwest', 'uaecentral', 'uaenorth', 'uksouth', 'ukwest', 'westcentralus', 'westeurope', 'westindia', 'westus', 'westus2', 'westus3') -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.HybridCompute/machines/extensions' -Role 'Azure Connected Machine Resource Administrator' -Effect (Param Effect) {
        Require 'type, publisher and provisioningState are as required' {
            Field 'Microsoft.HybridCompute/machines/extensions/type' | Must -Be 'AzureMonitorLinuxAgent'
            Field publisher | Must -Be 'Microsoft.Azure.Monitor'
            Field provisioningState | Must -Be 'Succeeded'
        }
        Deployment -TemplateFile './templates/845857af-0333-4c5d-bbbc-6076697da122.json' -Parameters ([ordered]@{
                vmName   = (Arm '[field(''name'')]')
                location = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

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