Bylaw

Gallery › Monitoring › Azure Community Policy

Configure Linux virtual machines to run AMA with cross subscription user-assigned managed identity-based authentication

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Adapted from built-in /providers/Microsoft.Authorization/policyDefinitions/ae8a10e6-19d6-44a3-a02d-a2bdfc707742 with minimal changes to support a cross subscription UAMI. This policy is meant to be assigned at Management Group Level, if you don't do this then you must assign manualy the permissions */read to the Policy Managed Idenity on the cross subscription UAMI.Automate the deployment of Azure Monitor Agent extension on your Linux virtual machines for collecting telemetry data from the guest OS.

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

Azure Policy JSONazurepolicy.json · 584 lines
{
    "name": "2bf130ac-424c-570d-aadf-3cd38fbf1157",
    "type": "Microsoft.Authorization/policyDefinitions",
    "properties": {
        "displayName": "Configure Linux virtual machines to run AMA with cross subscription user-assigned managed identity-based authentication",
        "mode": "Indexed",
        "description": "Adapted from built-in /providers/Microsoft.Authorization/policyDefinitions/ae8a10e6-19d6-44a3-a02d-a2bdfc707742 with minimal changes to support a cross subscription UAMI. This policy is meant to be assigned at Management Group Level, if you don't do this then you must assign manualy the permissions */read to the Policy Managed Idenity on the cross subscription UAMI.Automate the deployment of Azure Monitor Agent extension on your Linux virtual machines for collecting telemetry data from the guest OS.",
        "metadata": {
            "version": "1.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"
            },
            "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": ""
            },
            "userAssignedManagedIdentitySubscription": {
                "type": "String",
                "metadata": {
                    "displayName": "User-Assigned Managed Identity Subscription Id",
                    "description": "The subscription id 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": ""
            },
            "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 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://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": []
            },
            "allowedLocations": {
                "type": "Array",
                "metadata": {
                    "displayName": "Allowed Virtual Machine Locations",
                    "description": "List of Allowed Virtual Machine Locations"
                },
                "defaultValue": [
                    "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",
                    "chinaeast",
                    "chinaeast2",
                    "chinaeast3",
                    "chinanorth",
                    "chinanorth2",
                    "chinanorth3",
                    "usgovarizona",
                    "usgovtexas",
                    "usgovvirginia",
                    "usdodeast",
                    "usdodcentral"
                ]
            }
        },
        "policyRule": {
            "if": {
                "allOf": [
                    {
                        "field": "type",
                        "equals": "Microsoft.Compute/virtualMachines"
                    },
                    {
                        "field": "location",
                        "in": "[parameters('allowedLocations')]"
                    },
                    {
                        "anyOf": [
                            {
                                "allOf": [
                                    {
                                        "value": "[parameters('scopeToSupportedImages')]",
                                        "equals": false
                                    },
                                    {
                                        "field": "Microsoft.Compute/virtualMachines/storageProfile.osDisk.osType",
                                        "like": "Linux*"
                                    }
                                ]
                            },
                            {
                                "field": "Microsoft.Compute/imageId",
                                "in": "[parameters('listOfLinuxImageIdToInclude')]"
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "RedHat"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "in": [
                                            "RHEL",
                                            "RHEL-ARM64",
                                            "RHEL-BYOS",
                                            "RHEL-HA",
                                            "RHEL-SAP",
                                            "RHEL-SAP-APPS",
                                            "RHEL-SAP-HA"
                                        ]
                                    },
                                    {
                                        "anyOf": [
                                            {
                                                "field": "Microsoft.Compute/imageSku",
                                                "like": "7*"
                                            },
                                            {
                                                "field": "Microsoft.Compute/imageSku",
                                                "like": "8*"
                                            },
                                            {
                                                "field": "Microsoft.Compute/imageSku",
                                                "like": "rhel-lvm7*"
                                            },
                                            {
                                                "field": "Microsoft.Compute/imageSku",
                                                "like": "rhel-lvm8*"
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "SUSE"
                                    },
                                    {
                                        "anyOf": [
                                            {
                                                "allOf": [
                                                    {
                                                        "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": [
                                                    {
                                                        "anyOf": [
                                                            {
                                                                "field": "Microsoft.Compute/imageOffer",
                                                                "like": "sles-12*"
                                                            },
                                                            {
                                                                "field": "Microsoft.Compute/imageOffer",
                                                                "like": "sles-15*"
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "field": "Microsoft.Compute/imageSku",
                                                        "in": [
                                                            "gen1",
                                                            "gen2"
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "Canonical"
                                    },
                                    {
                                        "anyOf": [
                                            {
                                                "field": "Microsoft.Compute/imageOffer",
                                                "equals": "UbuntuServer"
                                            },
                                            {
                                                "field": "Microsoft.Compute/imageOffer",
                                                "like": "0001-com-ubuntu-server-*"
                                            },
                                            {
                                                "field": "Microsoft.Compute/imageOffer",
                                                "like": "0001-com-ubuntu-pro-*"
                                            }
                                        ]
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "in": [
                                            "14.04.0-lts",
                                            "14.04.1-lts",
                                            "14.04.2-lts",
                                            "14.04.3-lts",
                                            "14.04.4-lts",
                                            "14.04.5-lts",
                                            "16_04_0-lts-gen2",
                                            "16_04-lts-gen2",
                                            "16.04-lts",
                                            "16.04.0-lts",
                                            "18_04-lts-arm64",
                                            "18_04-lts-gen2",
                                            "18.04-lts",
                                            "20_04-lts-arm64",
                                            "20_04-lts-gen2",
                                            "20_04-lts",
                                            "22_04-lts-gen2",
                                            "22_04-lts",
                                            "pro-16_04-lts-gen2",
                                            "pro-16_04-lts",
                                            "pro-18_04-lts-gen2",
                                            "pro-18_04-lts",
                                            "pro-20_04-lts-gen2",
                                            "pro-20_04-lts",
                                            "pro-22_04-lts-gen2",
                                            "pro-22_04-lts"
                                        ]
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "Oracle"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "equals": "Oracle-Linux"
                                    },
                                    {
                                        "anyOf": [
                                            {
                                                "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": "almalinux"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "equals": "almalinux"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "like": "8*"
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "ctrliqinc1648673227698"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "like": "rocky-8*"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "like": "rocky-8*"
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "credativ"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "in": [
                                            "Debian"
                                        ]
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "equals": "9"
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "Debian"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "in": [
                                            "debian-10",
                                            "debian-11"
                                        ]
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "in": [
                                            "10",
                                            "10-gen2",
                                            "11",
                                            "11-gen2"
                                        ]
                                    }
                                ]
                            },
                            {
                                "allOf": [
                                    {
                                        "field": "Microsoft.Compute/imagePublisher",
                                        "equals": "microsoftcblmariner"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageOffer",
                                        "equals": "cbl-mariner"
                                    },
                                    {
                                        "field": "Microsoft.Compute/imageSku",
                                        "in": [
                                            "1-gen2",
                                            "cbl-mariner-1",
                                            "cbl-mariner-2",
                                            "cbl-mariner-2-arm64",
                                            "cbl-mariner-2-gen2"
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            "then": {
                "effect": "[parameters('effect')]",
                "details": {
                    "type": "Microsoft.Compute/virtualMachines/extensions",
                    "roleDefinitionIds": [
                        "/providers/microsoft.authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"
                    ],
                    "existenceCondition": {
                        "allOf": [
                            {
                                "field": "Microsoft.Compute/virtualMachines/extensions/type",
                                "equals": "AzureMonitorLinuxAgent"
                            },
                            {
                                "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
                                "equals": "Microsoft.Azure.Monitor"
                            },
                            {
                                "field": "Microsoft.Compute/virtualMachines/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"
                                    },
                                    "userAssignedManagedIdentity": {
                                        "type": "string"
                                    }
                                },
                                "variables": {
                                    "extensionName": "AzureMonitorLinuxAgent",
                                    "extensionPublisher": "Microsoft.Azure.Monitor",
                                    "extensionTypeHandlerVersion": "1.29",
                                    "extensionType": "AzureMonitorLinuxAgent"
                                },
                                "resources": [
                                    {
                                        "name": "[concat(parameters('vmName'), '/', variables('extensionName'))]",
                                        "type": "Microsoft.Compute/virtualMachines/extensions",
                                        "location": "[parameters('location')]",
                                        "apiVersion": "2019-07-01",
                                        "properties": {
                                            "publisher": "[variables('extensionPublisher')]",
                                            "type": "[variables('extensionType')]",
                                            "typeHandlerVersion": "[variables('extensionTypeHandlerVersion')]",
                                            "autoUpgradeMinorVersion": true,
                                            "enableAutomaticUpgrade": true,
                                            "settings": {
                                                "authentication": {
                                                    "managedIdentity": {
                                                        "identifier-name": "mi_res_id",
                                                        "identifier-value": "[parameters('userAssignedManagedIdentity')]"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                ]
                            },
                            "parameters": {
                                "vmName": {
                                    "value": "[field('name')]"
                                },
                                "location": {
                                    "value": "[field('location')]"
                                },
                                "userAssignedManagedIdentity": {
                                    "value": "[if(parameters('bringYourOwnUserAssignedManagedIdentity'), concat('/subscriptions/', parameters('userAssignedManagedIdentitySubscription'), '/resourceGroups/', parameters('userAssignedManagedIdentityResourceGroup'), '/providers/Microsoft.ManagedIdentity/userAssignedIdentities/', parameters('userAssignedManagedIdentityName')), concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-', field('location')))]"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Bylaw2bf130ac-424c-570d-aadf-3cd38fbf1157.bylaw.ps1 · 207 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2bf130ac-424c-570d-aadf-3cd38fbf1157' {

    Properties @{
        DisplayName = 'Configure Linux virtual machines to run AMA with cross subscription user-assigned managed identity-based authentication'
        Description = 'Adapted from built-in /providers/Microsoft.Authorization/policyDefinitions/ae8a10e6-19d6-44a3-a02d-a2bdfc707742 with minimal changes to support a cross subscription UAMI. This policy is meant to be assigned at Management Group Level, if you don''t do this then you must assign manualy the permissions */read to the Policy Managed Idenity on the cross subscription UAMI.Automate the deployment of Azure Monitor Agent extension on your Linux virtual machines for collecting telemetry data from the guest OS.'
        Version     = '1.0.0'
        Category    = 'Monitoring'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy.'
    }
    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 UserAssignedManagedIdentitySubscription @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Subscription Id'
        Description = 'The subscription id 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 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 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://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 AllowedLocations @{
        Type        = 'Array'
        Default     = @('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', 'chinaeast', 'chinaeast2', 'chinaeast3', 'chinanorth', 'chinanorth2', 'chinanorth3', 'usgovarizona', 'usgovtexas', 'usgovvirginia', 'usdodeast', 'usdodcentral')
        DisplayName = 'Allowed Virtual Machine Locations'
        Description = 'List of Allowed Virtual Machine Locations'
    }

    Resource 'Microsoft.Compute/virtualMachines' {

        When {
            Field location | Must -BeIn (Param AllowedLocations)
        }

        Require 'storageProfile.osDisk.osType is as required' {
            AnyOf {
                Param ScopeToSupportedImages | Must -Not -Be $false
                Field storageProfile.osDisk.osType | Must -Not -BeLike 'Linux*' -IfPresent
            }
        }

        Require 'imageId is not one of the ListOfLinuxImageIdToInclude parameter' {
            Field 'Microsoft.Compute/imageId' | Must -Not -BeIn (Param ListOfLinuxImageIdToInclude) -IfPresent
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'RedHat' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('RHEL', 'RHEL-ARM64', 'RHEL-BYOS', 'RHEL-HA', 'RHEL-SAP', 'RHEL-SAP-APPS', 'RHEL-SAP-HA') -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '7*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '8*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike 'rhel-lvm7*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike 'rhel-lvm8*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'SUSE' -IfPresent
                AllOf {
                    AnyOf {
                        Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('SLES', 'SLES-HPC', 'SLES-HPC-Priority', 'SLES-SAP', 'SLES-SAP-BYOS', 'SLES-Priority', 'SLES-BYOS', 'SLES-SAPCAL', 'SLES-Standard') -IfPresent
                        AllOf {
                            Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '12*' -IfPresent
                            Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '15*' -IfPresent
                        }
                    }
                    AnyOf {
                        AllOf {
                            Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'sles-12*' -IfPresent
                            Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'sles-15*' -IfPresent
                        }
                        Field 'Microsoft.Compute/imageSku' | Must -Not -BeIn @('gen1', 'gen2') -IfPresent
                    }
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'Canonical' -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'UbuntuServer' -IfPresent
                    Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '0001-com-ubuntu-server-*' -IfPresent
                    Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '0001-com-ubuntu-pro-*' -IfPresent
                }
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeIn @('14.04.0-lts', '14.04.1-lts', '14.04.2-lts', '14.04.3-lts', '14.04.4-lts', '14.04.5-lts', '16_04_0-lts-gen2', '16_04-lts-gen2', '16.04-lts', '16.04.0-lts', '18_04-lts-arm64', '18_04-lts-gen2', '18.04-lts', '20_04-lts-arm64', '20_04-lts-gen2', '20_04-lts', '22_04-lts-gen2', '22_04-lts', 'pro-16_04-lts-gen2', 'pro-16_04-lts', 'pro-18_04-lts-gen2', 'pro-18_04-lts', 'pro-20_04-lts-gen2', 'pro-20_04-lts', 'pro-22_04-lts-gen2', 'pro-22_04-lts') -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'Oracle' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'Oracle-Linux' -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '7*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '8*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'OpenLogic' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('CentOS', 'Centos-LVM', 'CentOS-SRIOV') -IfPresent
                AllOf {
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '6*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '7*' -IfPresent
                    Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '8*' -IfPresent
                }
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'cloudera' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'cloudera-centos-os' -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '7*' -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'almalinux' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'almalinux' -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '8*' -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'ctrliqinc1648673227698' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike 'rocky-8*' -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike 'rocky-8*' -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'credativ' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('Debian') -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -Be '9' -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'Debian' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('debian-10', 'debian-11') -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeIn @('10', '10-gen2', '11', '11-gen2') -IfPresent
            }
        }

        Require 'imagePublisher, imageOffer and imageSku are as required' {
            AnyOf {
                Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'microsoftcblmariner' -IfPresent
                Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'cbl-mariner' -IfPresent
                Field 'Microsoft.Compute/imageSku' | Must -Not -BeIn @('1-gen2', 'cbl-mariner-1', 'cbl-mariner-2', 'cbl-mariner-2-arm64', 'cbl-mariner-2-gen2') -IfPresent
            }
        }
    }

    DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Virtual Machine Contributor' -Effect (Param Effect) {
        Require 'type, publisher and provisioningState are as required' {
            Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'AzureMonitorLinuxAgent'
            Field publisher | Must -Be 'Microsoft.Azure.Monitor'
            Field provisioningState | Must -Be 'Succeeded'
        }
        Deployment -TemplateFile './templates/2bf130ac-424c-570d-aadf-3cd38fbf1157.json' -Parameters ([ordered]@{
                vmName                      = (Arm '[field(''name'')]')
                location                    = (Arm '[field(''location'')]')
                userAssignedManagedIdentity = (Arm '[if(parameters(''bringYourOwnUserAssignedManagedIdentity''), concat(''/subscriptions/'', parameters(''userAssignedManagedIdentitySubscription''), ''/resourceGroups/'', parameters(''userAssignedManagedIdentityResourceGroup''), ''/providers/Microsoft.ManagedIdentity/userAssignedIdentities/'', parameters(''userAssignedManagedIdentityName'')), concat(''/subscriptions/'', subscription().subscriptionId, ''/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-'', field(''location'')))]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/Monitoring/configure-ama-on-linux-vm-with-cross-subscription-uami/azurepolicy.json in Azure/Community-Policy, under the MIT licence.