Bylaw

Gallery › Cosmos DB › Azure Community Policy

Audit geo-replication for Azure Cosmos DB

Converted Policy Audit Disabled Mode all Version 1.0.0

This policy validates that an Azure Cosmos DB account is deployed to at least two regions.

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

Azure Policy JSONazurepolicy.json · 46 lines
{
  "name": "e73554a2-9ef4-4db7-8476-02b86896d946",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit geo-replication for Azure Cosmos DB",
    "description": "This policy validates that an Azure Cosmos DB account is deployed to at least two regions.",
    "metadata": {
      "category": "Cosmos DB",
      "version": "1.0.0"
    },
    "mode": "all",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.DocumentDB/databaseAccounts"
          },
          {
            "less": 2,
            "count": {
              "field": "Microsoft.DocumentDB/databaseAccounts/locations[*]"
            }
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawe73554a2-9ef4-4db7-8476-02b86896d946.bylaw.ps1 · 27 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e73554a2-9ef4-4db7-8476-02b86896d946' {

    Properties @{
        DisplayName = 'Audit geo-replication for Azure Cosmos DB'
        Description = 'This policy validates that an Azure Cosmos DB account is deployed to at least two regions.'
        Category    = 'Cosmos DB'
        Version     = '1.0.0'
        Mode        = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.DocumentDB/databaseAccounts' {

        Require 'locations is as required' {
            Count 'locations[*]' | Must -BeGreaterOrEqual 2
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Cosmos DB/audit-geo-replication-for-azure-cosmos-db/azurepolicy.json in Azure/Community-Policy, under the MIT licence.