Bylaw

Gallery › Monitoring › Azure Community Policy

Audit Diagnostic Settings for WVD Host Pools to Log Analytics workspace

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Audits the diagnostic settings for WVD Host Pools to stream to a regional Log Analytics workspace when any WVD Host Pool which is missing these diagnostic settings is created or updated.

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

Azure Policy JSONazurepolicy.json · 59 lines
{
  "name": "e4a5441a-fc32-4ae3-854f-7ff52dcde5be",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit Diagnostic Settings for WVD Host Pools to Log Analytics workspace",
    "description": "Audits the diagnostic settings for WVD Host Pools to stream to a regional Log Analytics workspace when any WVD Host Pool which is missing these diagnostic settings is created or updated.",
    "metadata": {
      "version": "1.0.0",
      "category": "Monitoring"
    },
    "mode": "All",
    "parameters": {
      "logsEnabled": {
        "type": "String",
        "metadata": {
          "displayName": "Enable logs",
          "description": "Whether to enable logs stream to the Log Analytics workspace - True or False"
        },
        "allowedValues": [
          "True",
          "False"
        ],
        "defaultValue": "True"
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.DesktopVirtualization/hostpools"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
                "equals": "[parameters('logsEnabled')]"
              }
            ]
          }
        }
      }
    }
  }
}
Bylawe4a5441a-fc32-4ae3-854f-7ff52dcde5be.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e4a5441a-fc32-4ae3-854f-7ff52dcde5be' {

    Properties @{
        DisplayName = 'Audit Diagnostic Settings for WVD Host Pools to Log Analytics workspace'
        Description = 'Audits the diagnostic settings for WVD Host Pools to stream to a regional Log Analytics workspace when any WVD Host Pool which is missing these diagnostic settings is created or updated.'
        Version     = '1.0.0'
        Category    = 'Monitoring'
        Mode        = 'All'
    }

    Parameter LogsEnabled @{
        AllowedValues = @('True', 'False')
        Default       = 'True'
        DisplayName   = 'Enable logs'
        Description   = 'Whether to enable logs stream to the Log Analytics workspace - True or False'
    }
    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.DesktopVirtualization/hostpools'

    AuditIfNotExists 'Microsoft.Insights/diagnosticSettings' -Effect (Param Effect) {
        Require 'logs.enabled is the LogsEnabled parameter' {
            Field logs.enabled | Must -Be (Param LogsEnabled)
        }
    }
}

Source: policyDefinitions/Monitoring/audit-diagnostic-settings-for-wvd-host-pools-to-log-analytics-workspace/azurepolicy.json in Azure/Community-Policy, under the MIT licence.