Bylaw

Gallery › Monitoring › Azure built-in policies

The legacy Log Analytics extension should not be installed on virtual machines

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 Windows virtual machines. 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_Windows_VM_Deny.json · 54 lines
{
  "properties": {
    "displayName": "The legacy Log Analytics extension should not be installed on virtual machines",
    "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 Windows virtual machines. 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": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/virtualMachines/extensions"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/extensions/publisher",
            "equals": "Microsoft.EnterpriseCloud.Monitoring"
          },
          {
            "field": "Microsoft.Compute/virtualMachines/extensions/type",
            "equals": "MicrosoftMonitoringAgent"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/d2185817-5b7e-473c-aadd-9de6ac114280",
  "name": "d2185817-5b7e-473c-aadd-9de6ac114280"
}
Bylawd2185817-5b7e-473c-aadd-9de6ac114280.bylaw.ps1 · 32 lines
# Converted from LogAnalyticsExtension_Windows_VM_Deny.json by ConvertTo-Bylaw.
Policy 'd2185817-5b7e-473c-aadd-9de6ac114280' {

    Properties @{
        DisplayName   = 'The legacy Log Analytics extension should not be installed on virtual machines'
        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 Windows virtual machines. 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 'Microsoft.Compute/virtualMachines/extensions' {

        When {
            Field publisher | Must -Be 'Microsoft.EnterpriseCloud.Monitoring'
        }

        Require 'type is not MicrosoftMonitoringAgent' {
            Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Not -Be 'MicrosoftMonitoringAgent' -IfPresent
        }
    }

    Effect (Param Effect)
}

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