Bylaw

Gallery › Monitoring › Azure built-in policies

Azure Monitor Logs for Application Insights should be linked to a Log Analytics workspace

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

Link the Application Insights component to a Log Analytics workspace for logs encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your data in Azure Monitor. Linking your component to a Log Analytics workspace that's enabled with a customer-managed key, ensures that your Application Insights logs meet this compliance requirement, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.

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

Azure Policy JSONApplicationInsightsComponent_WorkspaceAssociation_Deny.json · 61 lines
{
  "properties": {
    "displayName": "Azure Monitor Logs for Application Insights should be linked to a Log Analytics workspace",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Link the Application Insights component to a Log Analytics workspace for logs encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your data in Azure Monitor. Linking your component to a Log Analytics workspace that's enabled with a customer-managed key, ensures that your Application Insights logs meet this compliance requirement, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.",
    "metadata": {
      "version": "1.1.0",
      "category": "Monitoring"
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        },
        "allowedValues": [
          "audit",
          "Audit",
          "deny",
          "Deny",
          "disabled",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Insights/components"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Insights/components/WorkspaceResourceId",
                "equals": ""
              },
              {
                "field": "Microsoft.Insights/components/WorkspaceResourceId",
                "exists": "false"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/d550e854-df1a-4de9-bf44-cd894b39a95e",
  "name": "d550e854-df1a-4de9-bf44-cd894b39a95e"
}
Bylawd550e854-df1a-4de9-bf44-cd894b39a95e.bylaw.ps1 · 32 lines
# Converted from ApplicationInsightsComponent_WorkspaceAssociation_Deny.json by ConvertTo-Bylaw.
Policy 'd550e854-df1a-4de9-bf44-cd894b39a95e' {

    Properties @{
        DisplayName   = 'Azure Monitor Logs for Application Insights should be linked to a Log Analytics workspace'
        Description   = 'Link the Application Insights component to a Log Analytics workspace for logs encryption. Customer-managed keys are commonly required to meet regulatory compliance and for more control over the access to your data in Azure Monitor. Linking your component to a Log Analytics workspace that''s enabled with a customer-managed key, ensures that your Application Insights logs meet this compliance requirement, see https://docs.microsoft.com/azure/azure-monitor/platform/customer-managed-keys.'
        Version       = '1.1.0'
        Category      = 'Monitoring'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('audit', 'Audit', 'deny', 'Deny', 'disabled', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.Insights/components' {

        Require 'WorkspaceResourceId is not' {
            Field WorkspaceResourceId | Must -Not -Be '' -IfPresent
        }

        Require 'WorkspaceResourceId exists' {
            Field WorkspaceResourceId | Must -Exist
        }
    }

    Effect (Param Effect)
}

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