Bylaw

Gallery › Sovereignty › Azure built-in policies

[Preview]: Azure Service Bus geo-replication locations should use allowed regions

Converted Policy Audit Disabled Mode Indexed Version 1.0.0-preview Preview

Restrict the Azure regions where Service Bus data is actively replicated, including primary and secondary regions, to meet data residency and sovereignty requirements.

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

Azure Policy JSONServiceBusReplicaLocations_Audit.json · 64 lines
{
  "properties": {
    "displayName": "[Preview]: Azure Service Bus geo-replication locations should use allowed regions",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Restrict the Azure regions where Service Bus data is actively replicated, including primary and secondary regions, to meet data residency and sovereignty requirements.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Sovereignty",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "allowedGeoReplicationLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed geo-replication locations",
          "description": "The list of Azure regions where Service Bus data may be actively replicated.",
          "strongType": "location"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.ServiceBus/namespaces"
          },
          {
            "count": {
              "field": "Microsoft.ServiceBus/namespaces/geoDataReplication.locations[*]",
              "where": {
                "value": "[replace(toLower(current('Microsoft.ServiceBus/namespaces/geoDataReplication.locations[*].locationName')), ' ', '')]",
                "notIn": "[parameters('allowedGeoReplicationLocations')]"
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/9bf20ff2-0f28-47ea-ab41-0d070cf1d73b",
  "name": "9bf20ff2-0f28-47ea-ab41-0d070cf1d73b"
}
Bylaw9bf20ff2-0f28-47ea-ab41-0d070cf1d73b.bylaw.ps1 · 37 lines
# Converted from ServiceBusReplicaLocations_Audit.json by ConvertTo-Bylaw.
Policy '9bf20ff2-0f28-47ea-ab41-0d070cf1d73b' {

    Properties @{
        DisplayName   = '[Preview]: Azure Service Bus geo-replication locations should use allowed regions'
        Description   = 'Restrict the Azure regions where Service Bus data is actively replicated, including primary and secondary regions, to meet data residency and sovereignty requirements.'
        Version       = '1.0.0-preview'
        Category      = 'Sovereignty'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

    Parameter AllowedGeoReplicationLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed geo-replication locations'
        Description = 'The list of Azure regions where Service Bus data may be actively replicated.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.ServiceBus/namespaces' {

        Require 'geoDataReplication.locations is as required' {
            Count 'geoDataReplication.locations[*]' -Where {
                Arm '[replace(toLower(current(''Microsoft.ServiceBus/namespaces/geoDataReplication.locations[*].locationName'')), '' '', '''')]' | Must -Not -BeIn (Param AllowedGeoReplicationLocations)
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Sovereignty/ServiceBusReplicaLocations_Audit.json in Azure/azure-policy, under the MIT licence.