Gallery › Storage › Azure Community Policy
Audit diagnostic setting for selected resource types
Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0
This policy audit the existence of diagnostic setting and specific log analytics workspaceId for selected resource types.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 73 lines
{
"name": "18df4014-9705-4839-9bbf-91bb26f59766",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Audit diagnostic setting for selected resource types",
"description": "This policy audit the existence of diagnostic setting and specific log analytics workspaceId for selected resource types.",
"metadata": {
"category": "Storage",
"createdBy": "",
"updatedBy": null,
"updatedOn": null,
"version": "1.0.0"
},
"mode": "All",
"parameters": {
"listOfResourceTypes": {
"type": "Array",
"metadata": {
"displayName": "Resource Types",
"strongType": "resourceTypes"
}
},
"logAnalyticsWorkspaceId": {
"type": "String",
"metadata": {
"description": "Specify the Log Analytics workspace the logs should be streamed to.",
"displayName": "Log Analytics workspaceId",
"strongType": "omsWorkspace"
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"in": "[parameters('listOfResourceTypes')]"
},
"then": {
"details": {
"existenceCondition": {
"allOf": [
{
"equals": "true",
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled"
},
{
"equals": "true",
"field": "Microsoft.Insights/diagnosticSettings/metrics.enabled"
},
{
"equals": "[parameters('logAnalyticsWorkspaceId')]",
"field": "Microsoft.Insights/diagnosticSettings/workspaceId"
}
]
},
"type": "Microsoft.Insights/diagnosticSettings"
},
"effect": "[parameters('effect')]"
}
}
}
}Bylaw18df4014-9705-4839-9bbf-91bb26f59766.bylaw.ps1 · 44 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '18df4014-9705-4839-9bbf-91bb26f59766' {
Properties @{
DisplayName = 'Audit diagnostic setting for selected resource types'
Description = 'This policy audit the existence of diagnostic setting and specific log analytics workspaceId for selected resource types.'
Category = 'Storage'
Version = '1.0.0'
Mode = 'All'
}
Parameter ListOfResourceTypes @{
Type = 'Array'
DisplayName = 'Resource Types'
Metadata = [ordered]@{ strongType = 'resourceTypes' }
}
Parameter LogAnalyticsWorkspaceId @{
Type = 'String'
DisplayName = 'Log Analytics workspaceId'
Description = 'Specify the Log Analytics workspace the logs should be streamed to.'
Metadata = [ordered]@{ strongType = 'omsWorkspace' }
}
Parameter Effect @{
AllowedValues = @('AuditIfNotExists', 'Disabled')
Default = 'AuditIfNotExists'
DisplayName = 'Effect'
Description = 'AuditIfNotExists or Disabled the execution of the Policy'
}
Resource * {
Require 'type is not one of the ListOfResourceTypes parameter' {
Field type | Must -Not -BeIn (Param ListOfResourceTypes) -IfPresent
}
}
AuditIfNotExists 'Microsoft.Insights/diagnosticSettings' -Effect (Param Effect) {
Require 'logs.enabled, metrics.enabled and workspaceId are as required' {
Field logs.enabled | Must -Be 'true'
Field metrics.enabled | Must -Be 'true'
Field workspaceId | Must -Be (Param LogAnalyticsWorkspaceId)
}
}
}Source: policyDefinitions/Storage/audit-diagnostic-setting-for-selected-resource-types/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw