Gallery › Resilience › Azure built-in policies
[Preview]: Cosmos Database Accounts should be Zone Redundant
Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0-preview Preview
Cosmos Database Accounts can be configured to be Zone Redundant or not. If the 'enableMultipleWriteLocations' is set to 'true' then all locations must have a 'isZoneRedundant' property and it must be set to 'true'. If the 'enableMultipleWriteLocations' is set to 'false' then the primary location ('failoverPriority' set to 0) must have a 'isZoneRedundant' property and it must be set to 'true'. Enforcing this policy ensures Cosmos Database Accounts are appropriately configured for zone redundancy.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
{
"properties": {
"displayName": "[Preview]: Cosmos Database Accounts should be Zone Redundant",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Cosmos Database Accounts can be configured to be Zone Redundant or not. If the 'enableMultipleWriteLocations' is set to 'true' then all locations must have a 'isZoneRedundant' property and it must be set to 'true'. If the 'enableMultipleWriteLocations' is set to 'false' then the primary location ('failoverPriority' set to 0) must have a 'isZoneRedundant' property and it must be set to 'true'. Enforcing this policy ensures Cosmos Database Accounts are appropriately configured for zone redundancy.",
"metadata": {
"category": "Resilience",
"version": "1.0.0-preview",
"preview": true
},
"version": "1.0.0-preview",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group)."
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.DocumentDB/databaseAccounts"
},
{
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/enableMultipleWriteLocations",
"equals": true
},
{
"count": {
"field": "Microsoft.DocumentDB/databaseAccounts/Locations[*]",
"where": {
"anyOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/locations[*].isZoneRedundant",
"exists": false
},
{
"field": "Microsoft.DocumentDB/databaseAccounts/locations[*].isZoneRedundant",
"equals": false
}
]
}
},
"greater": 0
}
]
},
{
"allOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/enableMultipleWriteLocations",
"equals": false
},
{
"count": {
"field": "Microsoft.DocumentDB/databaseAccounts/Locations[*]",
"where": {
"allOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/locations[*].failoverPriority",
"equals": 0
},
{
"anyOf": [
{
"field": "Microsoft.DocumentDB/databaseAccounts/locations[*].isZoneRedundant",
"exists": false
},
{
"field": "Microsoft.DocumentDB/databaseAccounts/locations[*].isZoneRedundant",
"equals": false
}
]
}
]
}
},
"greater": 0
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.0.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/44c5a1f9-7ef6-4c38-880c-273e8f7a3c24",
"name": "44c5a1f9-7ef6-4c38-880c-273e8f7a3c24"
}# Converted from DocumentDB_databaseAccounts_ZoneRedundant_Audit.json by ConvertTo-Bylaw.
Policy '44c5a1f9-7ef6-4c38-880c-273e8f7a3c24' {
Properties @{
DisplayName = '[Preview]: Cosmos Database Accounts should be Zone Redundant'
Description = 'Cosmos Database Accounts can be configured to be Zone Redundant or not. If the ''enableMultipleWriteLocations'' is set to ''true'' then all locations must have a ''isZoneRedundant'' property and it must be set to ''true''. If the ''enableMultipleWriteLocations'' is set to ''false'' then the primary location (''failoverPriority'' set to 0) must have a ''isZoneRedundant'' property and it must be set to ''true''. Enforcing this policy ensures Cosmos Database Accounts are appropriately configured for zone redundancy.'
Category = 'Resilience'
Version = '1.0.0-preview'
Preview = $true
PolicyVersion = '1.0.0-preview'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'This parameter lets you choose the effect of the policy. If you choose Audit (default), the policy will only audit resources for compliance. If you choose Deny, the policy will deny the creation of non-compliant resources. If you choose Disabled, the policy will not enforce compliance (useful, for example, as a second assignment to ignore a subset of non-compliant resources in a single resource group).'
}
Resource 'Microsoft.DocumentDB/databaseAccounts' {
Require 'enableMultipleWriteLocations, Locations and isZoneRedundant are as required' {
AnyOf {
Field enableMultipleWriteLocations | Must -Not -Be $true -IfPresent
Each 'Locations[*]' {
Field isZoneRedundant | Must -Not -Be $false -Strict
}
}
}
Require 'enableMultipleWriteLocations, Locations, failoverPriority and 1 more are as required' {
AnyOf {
Field enableMultipleWriteLocations | Must -Not -Be $false -IfPresent
Each 'Locations[*]' -Where {
Field failoverPriority | Must -Be 0
} {
Field isZoneRedundant | Must -Not -Be $false -Strict
}
}
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Resilience/DocumentDB_databaseAccounts_ZoneRedundant_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw