Gallery › Monitoring › Azure built-in policies
Enable logging by category group for Event Grid System Topics (microsoft.eventgrid/systemtopics) to Storage
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Resource logs should be enabled to track activities and events that take place on your resources and give you visibility and insights into any changes that occur. This policy deploys a diagnostic setting using a category group to route logs to a Storage Account for Event Grid System Topics (microsoft.eventgrid/systemtopics).
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDS_ST_eventgrid-systemtopics_DINE.json · 187 lines
{
"properties": {
"displayName": "Enable logging by category group for Event Grid System Topics (microsoft.eventgrid/systemtopics) to Storage",
"description": "Resource logs should be enabled to track activities and events that take place on your resources and give you visibility and insights into any changes that occur. This policy deploys a diagnostic setting using a category group to route logs to a Storage Account for Event Grid System Topics (microsoft.eventgrid/systemtopics).",
"mode": "Indexed",
"policyType": "BuiltIn",
"version": "1.0.0",
"metadata": {
"category": "Monitoring",
"version": "1.0.0"
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"diagnosticSettingName": {
"type": "String",
"metadata": {
"displayName": "Diagnostic Setting Name",
"description": "Diagnostic Setting Name"
},
"defaultValue": "setByPolicy-Storage"
},
"categoryGroup": {
"type": "String",
"metadata": {
"displayName": "Category Group",
"description": "Diagnostic category group - none, audit, or allLogs."
},
"allowedValues": [
"audit",
"allLogs"
],
"defaultValue": "audit"
},
"resourceLocation": {
"type": "string",
"metadata": {
"displayName": "Resource Location",
"description": "Resource Location must be in the same location as the Storage Account.",
"strongType": "location"
}
},
"storageAccount": {
"type": "string",
"metadata": {
"displayName": "Storage Account",
"description": "Full path (resourceId) to the storage account.",
"assignPermissions": true
}
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "microsoft.eventgrid/systemtopics"
},
{
"field": "location",
"equals": "[parameters('resourceLocation')]"
}
]
},
"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/storageAccountId",
"equals": "[parameters('storageAccount')]"
}
]
},
"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"
},
"categoryGroup": {
"type": "String"
},
"storageAccount": {
"type": "string"
},
"resourceLocation": {
"type": "string"
},
"resourceName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "microsoft.eventgrid/systemtopics/providers/diagnosticSettings",
"apiVersion": "2021-05-01-preview",
"name": "[concat(parameters('resourceName'), '/', 'Microsoft.Insights/', parameters('diagnosticSettingName'))]",
"location": "[parameters('resourceLocation')]",
"properties": {
"storageAccountId": "[parameters('storageAccount')]",
"logs": [
{
"categoryGroup": "allLogs",
"enabled": "[equals(parameters('categoryGroup'), 'allLogs')]"
}
],
"metrics": []
}
}
],
"outputs": {
"policy": {
"type": "string",
"value": "[concat('Diagnostic setting ', parameters('diagnosticSettingName'), ' for type Event Grid System Topics (microsoft.eventgrid/systemtopics), resourceName ', parameters('resourceName'), ' to Storage Account ', parameters('storageAccount'), ' configured')]"
}
}
},
"parameters": {
"diagnosticSettingName": {
"value": "[parameters('diagnosticSettingName')]"
},
"categoryGroup": {
"value": "[parameters('categoryGroup')]"
},
"storageAccount": {
"value": "[parameters('storageAccount')]"
},
"resourceLocation": {
"value": "[field('location')]"
},
"resourceName": {
"value": "[field('name')]"
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"name": "22c8a30b-c5c1-4434-b837-2772543d3c3c",
"id": "/providers/Microsoft.Authorization/policyDefinitions/22c8a30b-c5c1-4434-b837-2772543d3c3c"
}Bylaw22c8a30b-c5c1-4434-b837-2772543d3c3c.bylaw.ps1 · 66 lines
# Converted from DS_ST_eventgrid-systemtopics_DINE.json by ConvertTo-Bylaw.
Policy '22c8a30b-c5c1-4434-b837-2772543d3c3c' {
Properties @{
DisplayName = 'Enable logging by category group for Event Grid System Topics (microsoft.eventgrid/systemtopics) to Storage'
Description = 'Resource logs should be enabled to track activities and events that take place on your resources and give you visibility and insights into any changes that occur. This policy deploys a diagnostic setting using a category group to route logs to a Storage Account for Event Grid System Topics (microsoft.eventgrid/systemtopics).'
Category = 'Monitoring'
Version = '1.0.0'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter DiagnosticSettingName @{
Default = 'setByPolicy-Storage'
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 ResourceLocation @{
Type = 'string'
DisplayName = 'Resource Location'
Description = 'Resource Location must be in the same location as the Storage Account.'
Metadata = [ordered]@{ strongType = 'location' }
}
Parameter StorageAccount @{
Type = 'string'
DisplayName = 'Storage Account'
Description = 'Full path (resourceId) to the storage account.'
Metadata = [ordered]@{ assignPermissions = $true }
}
Resource 'microsoft.eventgrid/systemtopics' {
Require 'location is not the ResourceLocation parameter' {
Field location | Must -Not -Be (Param ResourceLocation) -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 storageAccountId | Must -Be (Param StorageAccount)
}
Deployment -TemplateFile './templates/22c8a30b-c5c1-4434-b837-2772543d3c3c.json' -Parameters ([ordered]@{
diagnosticSettingName = (Param DiagnosticSettingName)
categoryGroup = (Param CategoryGroup)
storageAccount = (Param StorageAccount)
resourceLocation = (Arm '[field(''location'')]')
resourceName = (Arm '[field(''name'')]')
})
}
}Its deployment templates are written beside it:
templates/22c8a30b-c5c1-4434-b837-2772543d3c3c.json
Source: built-in-policies/policyDefinitions/Monitoring/DS_ST_eventgrid-systemtopics_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw