Bylaw

Gallery › Monitoring › Azure built-in policies

[Deprecated]: Enable logging by category group for microsoft.customproviders/resourceproviders to Log Analytics

Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.1.0-deprecated Deprecated

This policy is deprecated because Azure Custom Providers will be retired on October 31, 2026. For more information, see https://learn.microsoft.com/azure/azure-resource-manager/custom-providers/overview. This policy deploys a diagnostic setting using a category group to route logs from microsoft.customproviders/resourceproviders to a Log Analytics workspace.

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

Azure Policy JSONDS_LA_customproviders-resourceproviders_DINE.json · 193 lines
{
  "properties": {
    "displayName": "[Deprecated]: Enable logging by category group for microsoft.customproviders/resourceproviders to Log Analytics",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy is deprecated because Azure Custom Providers will be retired on October 31, 2026. For more information, see https://learn.microsoft.com/azure/azure-resource-manager/custom-providers/overview. This policy deploys a diagnostic setting using a category group to route logs from microsoft.customproviders/resourceproviders to a Log Analytics workspace.",
    "metadata": {
      "category": "Monitoring",
      "version": "1.1.0-deprecated",
      "deprecated": true
    },
    "version": "1.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "Disabled"
      },
      "diagnosticSettingName": {
        "type": "String",
        "metadata": {
          "displayName": "Diagnostic Setting Name",
          "description": "Diagnostic Setting Name"
        },
        "defaultValue": "setByPolicy-LogAnalytics"
      },
      "categoryGroup": {
        "type": "String",
        "metadata": {
          "displayName": "Category Group",
          "description": "Diagnostic category group - none, audit, or allLogs."
        },
        "allowedValues": [
          "audit",
          "allLogs"
        ],
        "defaultValue": "audit"
      },
      "resourceLocationList": {
        "type": "array",
        "metadata": {
          "displayName": "Resource Location List",
          "description": "Resource Location List to send logs to nearby Log Analytics. A single entry \"*\" selects all locations (default)."
        },
        "defaultValue": [
          "*"
        ]
      },
      "logAnalytics": {
        "type": "string",
        "metadata": {
          "displayName": "Log Analytics Workspace",
          "description": "Log Analytics Workspace",
          "strongType": "omsWorkspace",
          "assignPermissions": true
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "microsoft.customproviders/resourceproviders"
          },
          {
            "anyOf": [
              {
                "value": "[first(parameters('resourceLocationList'))]",
                "equals": "*"
              },
              {
                "field": "location",
                "in": "[parameters('resourceLocationList')]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "evaluationDelay": "AfterProvisioning",
          "existenceCondition": {
            "allOf": [
              {
                "count": {
                  "field": "Microsoft.Insights/diagnosticSettings/logs[*]",
                  "where": {
                    "allOf": [
                      {
                        "field": "Microsoft.Insights/diagnosticSettings/logs[*].enabled",
                        "equals": "[equals(parameters('categoryGroup'), 'allLogs')]"
                      },
                      {
                        "field": "microsoft.insights/diagnosticSettings/logs[*].categoryGroup",
                        "equals": "allLogs"
                      }
                    ]
                  }
                },
                "equals": 1
              },
              {
                "field": "Microsoft.Insights/diagnosticSettings/workspaceId",
                "equals": "[parameters('logAnalytics')]"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "diagnosticSettingName": {
                    "type": "string"
                  },
                  "logAnalytics": {
                    "type": "string"
                  },
                  "categoryGroup": {
                    "type": "String"
                  },
                  "resourceName": {
                    "type": "string"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "microsoft.customproviders/resourceproviders/providers/diagnosticSettings",
                    "apiVersion": "2021-05-01-preview",
                    "name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('diagnosticSettingName'))]",
                    "properties": {
                      "workspaceId": "[parameters('logAnalytics')]",
                      "logs": [
                        {
                          "categoryGroup": "allLogs",
                          "enabled": "[equals(parameters('categoryGroup'), 'allLogs')]"
                        }
                      ],
                      "metrics": []
                    }
                  }
                ],
                "outputs": {
                  "policy": {
                    "type": "string",
                    "value": "[concat('Diagnostic setting ', parameters('diagnosticSettingName'), ' for type microsoft.customproviders/resourceproviders, resourceName ', parameters('resourceName'), ' to Log Analytics ', parameters('logAnalytics'), ' configured')]"
                  }
                }
              },
              "parameters": {
                "diagnosticSettingName": {
                  "value": "[parameters('diagnosticSettingName')]"
                },
                "logAnalytics": {
                  "value": "[parameters('logAnalytics')]"
                },
                "categoryGroup": {
                  "value": "[parameters('categoryGroup')]"
                },
                "resourceName": {
                  "value": "[field('name')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "name": "65a1573e-cc90-412b-8db2-ba60731b0ea6",
  "id": "/providers/Microsoft.Authorization/policyDefinitions/65a1573e-cc90-412b-8db2-ba60731b0ea6"
}
Bylaw65a1573e-cc90-412b-8db2-ba60731b0ea6.bylaw.ps1 · 70 lines
# Converted from DS_LA_customproviders-resourceproviders_DINE.json by ConvertTo-Bylaw.
Policy '65a1573e-cc90-412b-8db2-ba60731b0ea6' {

    Properties @{
        DisplayName   = '[Deprecated]: Enable logging by category group for microsoft.customproviders/resourceproviders to Log Analytics'
        Description   = 'This policy is deprecated because Azure Custom Providers will be retired on October 31, 2026. For more information, see https://learn.microsoft.com/azure/azure-resource-manager/custom-providers/overview. This policy deploys a diagnostic setting using a category group to route logs from microsoft.customproviders/resourceproviders to a Log Analytics workspace.'
        Category      = 'Monitoring'
        Version       = '1.1.0-deprecated'
        Deprecated    = $true
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
        Default       = 'Disabled'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter DiagnosticSettingName @{
        Default     = 'setByPolicy-LogAnalytics'
        DisplayName = 'Diagnostic Setting Name'
        Description = 'Diagnostic Setting Name'
    }
    Parameter CategoryGroup @{
        AllowedValues = @('audit', 'allLogs')
        Default       = 'audit'
        DisplayName   = 'Category Group'
        Description   = 'Diagnostic category group - none, audit, or allLogs.'
    }
    Parameter ResourceLocationList @{
        Type        = 'array'
        Default     = @('*')
        DisplayName = 'Resource Location List'
        Description = 'Resource Location List to send logs to nearby Log Analytics. A single entry "*" selects all locations (default).'
    }
    Parameter LogAnalytics @{
        Type        = 'string'
        DisplayName = 'Log Analytics Workspace'
        Description = 'Log Analytics Workspace'
        Metadata    = [ordered]@{ strongType = 'omsWorkspace'; assignPermissions = $true }
    }

    Resource 'microsoft.customproviders/resourceproviders' {

        Require 'Requirement 1' {
            Arm '[first(parameters(''resourceLocationList''))]' | Must -Not -Be '*'
        }

        Require 'location is not one of the ResourceLocationList parameter' {
            Field location | Must -Not -BeIn (Param ResourceLocationList) -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.Insights/diagnosticSettings' -Role 'Log Analytics Contributor' -EvaluationDelay AfterProvisioning -Effect (Param Effect) {
        Require 'logs, enabled, categoryGroup and 1 more are as required' {
            Count 'logs[*]' -Where {
                Field enabled | Must -Be (Arm '[equals(parameters(''categoryGroup''), ''allLogs'')]')
                Field categoryGroup | Must -Be 'allLogs'
            } | Must -Be 1
            Field workspaceId | Must -Be (Param LogAnalytics)
        }
        Deployment -TemplateFile './templates/65a1573e-cc90-412b-8db2-ba60731b0ea6.json' -Parameters ([ordered]@{
                diagnosticSettingName = (Param DiagnosticSettingName)
                logAnalytics          = (Param LogAnalytics)
                categoryGroup         = (Param CategoryGroup)
                resourceName          = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

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