Bylaw

Gallery › Monitoring › Azure built-in policies

The legacy Log Analytics extension should not be installed on Azure Arc enabled Linux servers

Converted Policy Audit Deny Disabled Mode Indexed 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 Azure Arc enabled Linux servers. 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_HybridVM_Deny.json · 54 lines
{
  "properties": {
    "displayName": "The legacy Log Analytics extension should not be installed on Azure Arc enabled Linux servers",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "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 Azure Arc enabled Linux servers. 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.HybridCompute/machines/extensions"
          },
          {
            "field": "Microsoft.HybridCompute/machines/extensions/publisher",
            "equals": "Microsoft.EnterpriseCloud.Monitoring"
          },
          {
            "field": "Microsoft.HybridCompute/machines/extensions/type",
            "equals": "OmsAgentForLinux"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/bd58d393-162c-4134-bcd6-a6a5484a37a1",
  "name": "bd58d393-162c-4134-bcd6-a6a5484a37a1"
}
Bylawbd58d393-162c-4134-bcd6-a6a5484a37a1.bylaw.ps1 · 32 lines
# Converted from LogAnalyticsExtension_Linux_HybridVM_Deny.json by ConvertTo-Bylaw.
Policy 'bd58d393-162c-4134-bcd6-a6a5484a37a1' {

    Properties @{
        DisplayName   = 'The legacy Log Analytics extension should not be installed on Azure Arc enabled Linux servers'
        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 Azure Arc enabled Linux servers. Learn more: https://aka.ms/migratetoAMA'
        Version       = '1.0.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.HybridCompute/machines/extensions' {

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

        Require 'type is not OmsAgentForLinux' {
            Field 'Microsoft.HybridCompute/machines/extensions/type' | Must -Not -Be 'OmsAgentForLinux' -IfPresent
        }
    }

    Effect (Param Effect)
}

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