Bylaw

Gallery › Monitoring › Azure built-in policies

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

Converted Initiative Version 3.2.0

Monitor and secure your Windows 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_WindowsPlatform_EnableDCR.json · 126 lines
{
  "properties": {
    "displayName": "Configure Windows machines to run Azure Monitor Agent and associate them to a Data Collection Rule",
    "policyType": "BuiltIn",
    "description": "Monitor and secure your Windows 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
      },
      "listOfWindowsImageIdToInclude": {
        "type": "Array",
        "metadata": {
          "displayName": "Additional Virtual Machine Images",
          "description": "List of virtual machine images that have supported Windows 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 point to.",
          "portalReview": "true"
        }
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/ca817e41-e85a-4783-bc7f-dc532d36235e",
        "definitionVersion": "4.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitoringAgentWindows",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfWindowsImageIdToInclude": {
            "value": "[parameters('listOfWindowsImageIdToInclude')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/4efbd9d8-6bc6-45f6-9be2-7fe9dd5d89ff",
        "definitionVersion": "3.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitorAgentWindowsVMSS",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfWindowsImageIdToInclude": {
            "value": "[parameters('listOfWindowsImageIdToInclude')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/94f686d6-9a24-4e19-91f1-de937dc171a4",
        "definitionVersion": "2.*.*",
        "policyDefinitionReferenceId": "deployAzureMonitorAgentWindowsHybridVM",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/eab1f514-22e3-42e3-9a1f-e1dc9199355c",
        "definitionVersion": "4.*.*",
        "policyDefinitionReferenceId": "associateDataCollectionRuleWindows",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "scopeToSupportedImages": {
            "value": "[parameters('scopeToSupportedImages')]"
          },
          "listOfWindowsImageIdToInclude": {
            "value": "[parameters('listOfWindowsImageIdToInclude')]"
          },
          "DcrResourceId": {
            "value": "[parameters('DcrResourceId')]"
          },
          "resourceType": {
            "value": "Microsoft.Insights/dataCollectionRules"
          }
        }
      }
    ],
    "versions": [
      "3.2.0",
      "3.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/9575b8b7-78ab-4281-b53b-d3c1ace2260b",
  "name": "9575b8b7-78ab-4281-b53b-d3c1ace2260b"
}
Bylaw9575b8b7-78ab-4281-b53b-d3c1ace2260b.bylaw.ps1 · 82 lines
# Converted from AzureMonitor_WindowsPlatform_EnableDCR.json by ConvertTo-Bylaw.
Initiative '9575b8b7-78ab-4281-b53b-d3c1ace2260b' {

    Properties @{
        DisplayName   = 'Configure Windows machines to run Azure Monitor Agent and associate them to a Data Collection Rule'
        Description   = 'Monitor and secure your Windows 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 ListOfWindowsImageIdToInclude @{
        Type        = 'Array'
        Default     = @()
        DisplayName = 'Additional Virtual Machine Images'
        Description = 'List of virtual machine images that have supported Windows 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 point to.'
        JsonName    = 'DcrResourceId'
        Metadata    = [ordered]@{ portalReview = 'true' }
    }

    PolicyDefinition @{
        Id          = 'ca817e41-e85a-4783-bc7f-dc532d36235e'
        ReferenceId = 'deployAzureMonitoringAgentWindows'
        Version     = '4.*.*'
        Parameters  = [ordered]@{
            effect                        = (Param Effect)
            scopeToSupportedImages        = (Param ScopeToSupportedImages)
            listOfWindowsImageIdToInclude = (Param ListOfWindowsImageIdToInclude)
        }
    }

    PolicyDefinition @{
        Id          = '4efbd9d8-6bc6-45f6-9be2-7fe9dd5d89ff'
        ReferenceId = 'deployAzureMonitorAgentWindowsVMSS'
        Version     = '3.*.*'
        Parameters  = [ordered]@{
            effect                        = (Param Effect)
            scopeToSupportedImages        = (Param ScopeToSupportedImages)
            listOfWindowsImageIdToInclude = (Param ListOfWindowsImageIdToInclude)
        }
    }

    PolicyDefinition @{
        Id          = '94f686d6-9a24-4e19-91f1-de937dc171a4'
        ReferenceId = 'deployAzureMonitorAgentWindowsHybridVM'
        Version     = '2.*.*'
        Parameters  = @{
            effect = (Param Effect)
        }
    }

    PolicyDefinition @{
        Id          = 'eab1f514-22e3-42e3-9a1f-e1dc9199355c'
        ReferenceId = 'associateDataCollectionRuleWindows'
        Version     = '4.*.*'
        Parameters  = [ordered]@{
            effect                        = (Param Effect)
            scopeToSupportedImages        = (Param ScopeToSupportedImages)
            listOfWindowsImageIdToInclude = (Param ListOfWindowsImageIdToInclude)
            DcrResourceId                 = (Param DcrResourceId)
            resourceType                  = 'Microsoft.Insights/dataCollectionRules'
        }
    }
}

Members (4)

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