Gallery › Backup › Azure built-in policies
Deploy Diagnostic Settings for Recovery Services Vault to Log Analytics workspace for resource specific categories.
Uses Condition Policy DeployIfNotExists Mode Indexed Version 1.0.2
Deploy Diagnostic Settings for Recovery Services Vault to stream to Log Analytics workspace for Resource specific categories. If any of the Resource specific categories are not enabled, a new diagnostic setting is created.
ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.
Azure Policy JSONEnableRecoveryServiceVaultDiagnosticSetting_DINE.json · 193 lines
{
"properties": {
"displayName": "Deploy Diagnostic Settings for Recovery Services Vault to Log Analytics workspace for resource specific categories.",
"policyType": "BuiltIn",
"description": "Deploy Diagnostic Settings for Recovery Services Vault to stream to Log Analytics workspace for Resource specific categories. If any of the Resource specific categories are not enabled, a new diagnostic setting is created.",
"mode": "Indexed",
"metadata": {
"version": "1.0.2",
"category": "Backup"
},
"version": "1.0.2",
"parameters": {
"profileName": {
"type": "String",
"metadata": {
"displayName": "Profile name",
"description": "The diagnostic settings profile name"
},
"defaultValue": "setbypolicy_logAnalytics"
},
"logAnalytics": {
"type": "String",
"metadata": {
"displayName": "Log Analytics workspace",
"description": "Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant 'Log Analytics Contributor' permissions (or similar) to the policy assignment's principal ID.",
"strongType": "omsWorkspace",
"assignPermissions": true
}
},
"tagName": {
"type": "String",
"metadata": {
"displayName": "Exclusion Tag Name",
"description": "Name of the tag to use for excluding vaults from this policy. This should be used along with the Exclusion Tag Value parameter."
},
"defaultValue": ""
},
"tagValue": {
"type": "String",
"metadata": {
"displayName": "Exclusion Tag Value",
"description": "Value of the tag to use for excluding vaults from this policy. This should be used along with the Exclusion Tag Name parameter."
},
"defaultValue": ""
}
},
"policyRule": {
"if": {
"allof": [
{
"field": "type",
"equals": "Microsoft.RecoveryServices/vaults"
},
{
"not": {
"field": "[concat('tags[',parameters('tagName'), ']')]",
"equals": "[parameters('tagValue')]"
}
}
]
},
"then": {
"effect": "deployIfNotExists",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"existenceCondition": {
"allof": [
{
"count": {
"field": "Microsoft.Insights/diagnosticSettings/logs[*]",
"where": {
"allof": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].Category",
"in": [
"CoreAzureBackup",
"AddonAzureBackupJobs",
"AddonAzureBackupAlerts",
"AddonAzureBackupPolicy",
"AddonAzureBackupStorage",
"AddonAzureBackupProtectedInstance"
]
},
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].Enabled",
"equals": "True"
}
]
}
},
"Equals": 6
},
{
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"notEquals": ""
},
{
"field": "Microsoft.Insights/diagnosticSettings/logAnalyticsDestinationType",
"equals": "Dedicated"
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": {
"type": "string"
},
"logAnalytics": {
"type": "string"
},
"profileName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.RecoveryServices/vaults/providers/diagnosticSettings",
"apiVersion": "2017-05-01-preview",
"name": "[concat(parameters('vaultName'), '/', 'Microsoft.Insights/', parameters('profileName'))]",
"dependsOn": [],
"properties": {
"workspaceId": "[parameters('logAnalytics')]",
"logAnalyticsDestinationType": "Dedicated",
"metrics": [],
"logs": [
{
"category": "CoreAzureBackup",
"enabled": "true"
},
{
"category": "AddonAzureBackupAlerts",
"enabled": "true"
},
{
"category": "AddonAzureBackupJobs",
"enabled": "true"
},
{
"category": "AddonAzureBackupPolicy",
"enabled": "true"
},
{
"category": "AddonAzureBackupProtectedInstance",
"enabled": "true"
},
{
"category": "AddonAzureBackupStorage",
"enabled": "true"
}
]
}
}
],
"outputs": {
"policy": {
"type": "string",
"value": "[concat(parameters('logAnalytics'), 'configured for resource logs for ', ': ', parameters('vaultName'), '/', 'Microsoft.Insights/', parameters('profileName'))]"
}
}
},
"parameters": {
"logAnalytics": {
"value": "[parameters('logAnalytics')]"
},
"vaultName": {
"value": "[field('name')]"
},
"profileName": {
"value": "[parameters('profileName')]"
}
}
}
}
}
}
},
"versions": [
"1.0.2"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/c717fb0c-d118-4c43-ab3d-ece30ac81fb3",
"name": "c717fb0c-d118-4c43-ab3d-ece30ac81fb3"
}Bylawc717fb0c-d118-4c43-ab3d-ece30ac81fb3.bylaw.ps1 · 57 lines
# Converted from EnableRecoveryServiceVaultDiagnosticSetting_DINE.json by ConvertTo-Bylaw.
Policy 'c717fb0c-d118-4c43-ab3d-ece30ac81fb3' {
Properties @{
DisplayName = 'Deploy Diagnostic Settings for Recovery Services Vault to Log Analytics workspace for resource specific categories.'
Description = 'Deploy Diagnostic Settings for Recovery Services Vault to stream to Log Analytics workspace for Resource specific categories. If any of the Resource specific categories are not enabled, a new diagnostic setting is created.'
Version = '1.0.2'
Category = 'Backup'
PolicyVersion = '1.0.2'
Mode = 'Indexed'
}
Parameter ProfileName @{
Default = 'setbypolicy_logAnalytics'
DisplayName = 'Profile name'
Description = 'The diagnostic settings profile name'
}
Parameter LogAnalytics @{
Type = 'String'
DisplayName = 'Log Analytics workspace'
Description = 'Select Log Analytics workspace from dropdown list. If this workspace is outside of the scope of the assignment you must manually grant ''Log Analytics Contributor'' permissions (or similar) to the policy assignment''s principal ID.'
Metadata = [ordered]@{ strongType = 'omsWorkspace'; assignPermissions = $true }
}
Parameter TagName @{
Default = ''
DisplayName = 'Exclusion Tag Name'
Description = 'Name of the tag to use for excluding vaults from this policy. This should be used along with the Exclusion Tag Value parameter.'
}
Parameter TagValue @{
Default = ''
DisplayName = 'Exclusion Tag Value'
Description = 'Value of the tag to use for excluding vaults from this policy. This should be used along with the Exclusion Tag Name parameter.'
}
Resource 'Microsoft.RecoveryServices/vaults' {
Require '[concat(''''tags['''',parameters(''''tagName''''), '''']'''')] is as required' {
Condition -Violation '{ "field": "[concat(''tags['',parameters(''tagName''), '']'')]", "notEquals": "[parameters(''tagValue'')]" }'
}
}
DeployIfNotExists 'Microsoft.Insights/diagnosticSettings' -Role 'Monitoring Contributor', 'Log Analytics Contributor' {
Require 'logs, Category, Enabled and 2 more are as required' {
Count 'logs[*]' -Where {
Field Category | Must -BeIn @('CoreAzureBackup', 'AddonAzureBackupJobs', 'AddonAzureBackupAlerts', 'AddonAzureBackupPolicy', 'AddonAzureBackupStorage', 'AddonAzureBackupProtectedInstance')
Field Enabled | Must -Be 'True'
} | Must -Be 6
Field workspaceId | Must -Not -Be '' -IfPresent
Field logAnalyticsDestinationType | Must -Be 'Dedicated'
}
Deployment -TemplateFile './templates/c717fb0c-d118-4c43-ab3d-ece30ac81fb3.json' -Parameters ([ordered]@{
logAnalytics = (Param LogAnalytics)
vaultName = (Arm '[field(''name'')]')
profileName = (Param ProfileName)
})
}
}Its deployment templates are written beside it:
templates/c717fb0c-d118-4c43-ab3d-ece30ac81fb3.json
Source: built-in-policies/policyDefinitions/Backup/EnableRecoveryServiceVaultDiagnosticSetting_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw