Bylaw

Gallery › Monitoring › Azure built-in policies

The legacy Log Analytics extension should not be installed on Linux virtual machine scale sets

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Automatically prevent installation of the legacy Log Analytics Agent as the final step of migrating from legacy agents to Azure Monitor Agent. After you have uninstalled existing legacy extensions, this policy will deny all future installations of the legacy agent extension on Linux virtual machine scale sets. Learn more: https://aka.ms/migratetoAMA

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

Azure Policy JSONLogAnalyticsExtension_Linux_VMSS_Deny.json · 76 lines
{
  "properties": {
    "displayName": "The legacy Log Analytics extension should not be installed on Linux virtual machine scale sets",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Automatically prevent installation of the legacy Log Analytics Agent as the final step of migrating from legacy agents to Azure Monitor Agent. After you have uninstalled existing legacy extensions, this policy will deny all future installations of the legacy agent extension on Linux virtual machine scale sets. Learn more: https://aka.ms/migratetoAMA",
    "metadata": {
      "version": "1.0.0",
      "category": "Monitoring"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Compute/virtualMachineScaleSets/extensions"
              },
              {
                "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/publisher",
                "equals": "Microsoft.EnterpriseCloud.Monitoring"
              },
              {
                "field": "Microsoft.Compute/virtualMachineScaleSets/extensions/type",
                "equals": "OmsAgentForLinux"
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Compute/virtualMachineScaleSets"
              },
              {
                "count": {
                  "field": "Microsoft.Compute/VirtualMachineScaleSets/extensionProfile.extensions[*]",
                  "where": {
                    "field": "Microsoft.Compute/VirtualMachineScaleSets/extensionProfile.extensions[*].type",
                    "equals": "OmsAgentForLinux"
                  }
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/383c45fa-8b64-4d1c-aa9f-e69d2d879aa4",
  "name": "383c45fa-8b64-4d1c-aa9f-e69d2d879aa4"
}
Bylaw383c45fa-8b64-4d1c-aa9f-e69d2d879aa4.bylaw.ps1 · 41 lines
# Converted from LogAnalyticsExtension_Linux_VMSS_Deny.json by ConvertTo-Bylaw.
Policy '383c45fa-8b64-4d1c-aa9f-e69d2d879aa4' {

    Properties @{
        DisplayName   = 'The legacy Log Analytics extension should not be installed on Linux virtual machine scale sets'
        Description   = 'Automatically prevent installation of the legacy Log Analytics Agent as the final step of migrating from legacy agents to Azure Monitor Agent. After you have uninstalled existing legacy extensions, this policy will deny all future installations of the legacy agent extension on Linux virtual machine scale sets. Learn more: https://aka.ms/migratetoAMA'
        Version       = '1.0.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource * {

        Require 'type and publisher are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Compute/virtualMachineScaleSets/extensions' -IfPresent
                Field 'Microsoft.Compute/virtualMachineScaleSets/extensions/publisher' | Must -Not -Be 'Microsoft.EnterpriseCloud.Monitoring' -IfPresent
                Field 'Microsoft.Compute/virtualMachineScaleSets/extensions/type' | Must -Not -Be 'OmsAgentForLinux' -IfPresent
            }
        }

        Require 'type and extensionProfile.extensions are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Compute/virtualMachineScaleSets' -IfPresent
                Each 'Microsoft.Compute/VirtualMachineScaleSets/extensionProfile.extensions[*]' {
                    Field type | Must -Not -Be 'OmsAgentForLinux'
                }
            }
        }
    }

    Effect (Param Effect)
}

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