last sync: 2021-Nov-26 17:15:01 UTC

Azure Policy definition

Configure Linux machines to be associated with a Data Collection Rule

Name Configure Linux machines to be associated with a Data Collection Rule
Azure Portal
Id 2ea82cdd-f2e8-4500-af75-67a2e084ca74
Version 2.0.0
details on versioning
Category Monitoring
Microsoft docs
Description Deploy a Data Collection Rule Association to link a Linux virtual machine, virtual machine scale set, or Arc machine to the specified Data Collection Rule. The list of locations and OS images are updated over time as support is increased.
Mode Indexed
Type BuiltIn
Preview FALSE
Deprecated FALSE
Effect Default: DeployIfNotExists
Allowed: (DeployIfNotExists, Disabled)
Used RBAC Role
Role Name Role Id
Monitoring Contributor 749f88d5-cbae-40b8-bcfc-e573ddc772fa
Log Analytics Contributor 92aaf0da-9dab-42b6-94a3-d43ce8d16293
History
Date/Time (UTC ymd) (i) Change type Change detail
2021-10-19 19:10:32 change Major (1.0.0 > 2.0.0)
2021-05-26 13:43:16 add 2ea82cdd-f2e8-4500-af75-67a2e084ca74
Used in Initiatives
Initiative DisplayName Initiative Id Initiative Category State
Configure Linux machines to run Azure Monitor Agent and associate them to a Data Collection Rule 118f04da-0375-44d1-84e3-0fd9e1849403 Monitoring GA
JSON Changes

JSON
{
  "displayName": "Configure Linux machines to be associated with a Data Collection Rule",
  "policyType": "BuiltIn",
  "mode": "Indexed",
  "description": "Deploy a Data Collection Rule Association to link a Linux virtual machine, virtual machine scale set, or Arc machine to the specified Data Collection Rule. The list of locations and OS images are updated over time as support is increased.",
  "metadata": {
    "version": "2.0.0",
    "category": "Monitoring"
  },
  "parameters": {
    "effect": {
      "type": "String",
      "metadata": {
        "displayName": "Effect",
        "description": "Enable or disable the execution of the policy."
      },
      "allowedValues": [
        "DeployIfNotExists",
        "Disabled"
      ],
      "defaultValue": "DeployIfNotExists"
    },
    "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//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 to be applied on the virtual machines in scope."
      }
    }
  },
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "location",
          "in": [
            "australiacentral",
            "australiaeast",
            "australiasoutheast",
            "brazilsouth",
            "canadacentral",
            "canadaeast",
            "centralindia",
            "centralus",
            "eastasia",
            "eastus2euap",
            "eastus",
            "eastus2",
            "francecentral",
            "germanywestcentral",
            "japaneast",
            "japanwest",
            "jioindiawest",
            "koreacentral",
            "koreasouth",
            "northcentralus",
            "northeurope",
            "norwayeast",
            "southafricanorth",
            "southcentralus",
            "southeastasia",
            "southindia",
            "switzerlandnorth",
            "uaenorth",
            "uksouth",
            "ukwest",
            "westcentralus",
            "westeurope",
            "westindia",
            "westus",
            "westus2"
          ]
        },
        {
          "anyOf": [
            {
              "allOf": [
                {
                  "field": "type",
                  "equals": "Microsoft.HybridCompute/machines"
                },
                {
                  "field": "Microsoft.HybridCompute/machines/osName",
                  "equals": "linux"
                }
              ]
            },
            {
              "allOf": [
                {
                  "anyOf": [
                    {
                      "field": "type",
                      "equals": "Microsoft.Compute/virtualMachines"
                    },
                    {
                      "field": "type",
                      "equals": "Microsoft.Compute/virtualMachineScaleSets"
                    }
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageId",
                      "in": "[parameters('listOfLinuxImageIdToInclude')]"
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "RedHat"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "in": [
                            "RHEL",
                            "RHEL-SAP-HANA"
                          ]
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "6*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "7*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "8*"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "SUSE"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "in": [
                            "SLES",
                            "SLES-HPC",
                            "SLES-HPC-Priority",
                            "SLES-SAP",
                            "SLES-SAP-BYOS",
                            "SLES-Priority",
                            "SLES-BYOS",
                            "SLES-SAPCAL",
                            "SLES-Standard"
                          ]
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "12*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "15*"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "Canonical"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "equals": "UbuntuServer"
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "14.04*LTS"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "16.04*LTS"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "18.04*LTS"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "Canonical"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "equals": "0001-com-ubuntu-server-focal"
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "20_04-lts*"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "Oracle"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "equals": "Oracle-Linux"
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "6*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "7*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "8*"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "OpenLogic"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "in": [
                            "CentOS",
                            "Centos-LVM",
                            "CentOS-SRIOV"
                          ]
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "6*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "7*"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "8*"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "cloudera"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "equals": "cloudera-centos-os"
                        },
                        {
                          "field": "Microsoft.Compute/imageSku",
                          "like": "7*"
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "credativ"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "in": [
                            "debian"
                          ]
                        },
                        {
                          "anyOf": [
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "8"
                            },
                            {
                              "field": "Microsoft.Compute/imageSku",
                              "like": "9"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "allOf": [
                        {
                          "field": "Microsoft.Compute/imagePublisher",
                          "equals": "Debian"
                        },
                        {
                          "field": "Microsoft.Compute/imageOffer",
                          "in": [
                            "debian-10"
                          ]
                        },
                        {
                          "field": "Microsoft.Compute/imageSku",
                          "like": "10"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    "then": {
      "effect": "[parameters('effect')]",
      "details": {
        "type": "Microsoft.Insights/dataCollectionRuleAssociations",
        "roleDefinitionIds": [
          "/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
          "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
        ],
        "existenceCondition": {
          "field": "Microsoft.Insights/dataCollectionRuleAssociations/dataCollectionRuleId",
          "equals": "[parameters('dcrResourceId')]"
        },
        "deployment": {
          "properties": {
            "mode": "incremental",
            "template": {
              "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "parameters": {
                "resourceName": {
                  "type": "string"
                },
                "location": {
                  "type": "string"
                },
                "dcrResourceId": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                }
              },
              "variables": {
                "associationName": "[concat('assoc-', uniqueString(parameters('dcrResourceId')))]"
              },
              "resources": [
                {
                  "condition": "[equals(toLower(parameters('type')), 'microsoft.compute/virtualmachines')]",
                  "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', variables('associationName'))]",
                  "type": "Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations",
                  "location": "[parameters('location')]",
                  "apiVersion": "2019-11-01-preview",
                  "properties": {
                    "dataCollectionRuleId": "[parameters('dcrResourceId')]"
                  }
                },
                {
                  "condition": "[equals(toLower(parameters('type')), 'microsoft.compute/virtualmachinescalesets')]",
                  "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', variables('associationName'))]",
                  "type": "Microsoft.Compute/virtualMachineScaleSets/providers/dataCollectionRuleAssociations",
                  "location": "[parameters('location')]",
                  "apiVersion": "2019-11-01-preview",
                  "properties": {
                    "dataCollectionRuleId": "[parameters('dcrResourceId')]"
                  }
                },
                {
                  "condition": "[equals(toLower(parameters('type')), 'microsoft.hybridcompute/machines')]",
                  "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', variables('associationName'))]",
                  "type": "Microsoft.HybridCompute/machines/providers/dataCollectionRuleAssociations",
                  "location": "[parameters('location')]",
                  "apiVersion": "2019-11-01-preview",
                  "properties": {
                    "dataCollectionRuleId": "[parameters('dcrResourceId')]"
                  }
                }
              ]
            },
            "parameters": {
              "resourceName": {
                "value": "[field('name')]"
              },
              "location": {
                "value": "[field('location')]"
              },
              "dcrResourceId": {
                "value": "[parameters('dcrResourceId')]"
              },
              "type": {
                "value": "[field('type')]"
              }
            }
          }
        }
      }
    }
  }
}