Bylaw

Gallery › Sovereignty › Azure built-in policies

[Preview]: Azure SQL Database failover groups should use allowed partner locations

Converted Policy Audit Disabled Mode All Version 1.0.0-preview Preview

Keep Azure SQL Database failover-group partners within approved regions to help meet data residency requirements. Only configured partner server locations are evaluated; database default secondary locations, standalone active geo-replication links, and backup locations are not evaluated.

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

Azure Policy JSONSqlFailoverGroupPartnerLocations_Audit.json · 64 lines
{
  "properties": {
    "displayName": "[Preview]: Azure SQL Database failover groups should use allowed partner locations",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Keep Azure SQL Database failover-group partners within approved regions to help meet data residency requirements. Only configured partner server locations are evaluated; database default secondary locations, standalone active geo-replication links, and backup locations are not evaluated.",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Sovereignty",
      "preview": true
    },
    "version": "1.0.0-preview",
    "parameters": {
      "allowedPartnerLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Allowed partner locations",
          "description": "The list of Azure regions where Azure SQL Database failover-group partner servers are allowed.",
          "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.Sql/servers/failoverGroups"
          },
          {
            "count": {
              "field": "Microsoft.Sql/servers/failoverGroups/partnerServers[*]",
              "where": {
                "value": "[replace(toLower(string(current('Microsoft.Sql/servers/failoverGroups/partnerServers[*].location'))), ' ', '')]",
                "notIn": "[parameters('allowedPartnerLocations')]"
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e4bff06e-8af8-455b-8bec-58515205f65b",
  "name": "e4bff06e-8af8-455b-8bec-58515205f65b"
}
Bylawe4bff06e-8af8-455b-8bec-58515205f65b.bylaw.ps1 · 37 lines
# Converted from SqlFailoverGroupPartnerLocations_Audit.json by ConvertTo-Bylaw.
Policy 'e4bff06e-8af8-455b-8bec-58515205f65b' {

    Properties @{
        DisplayName   = '[Preview]: Azure SQL Database failover groups should use allowed partner locations'
        Description   = 'Keep Azure SQL Database failover-group partners within approved regions to help meet data residency requirements. Only configured partner server locations are evaluated; database default secondary locations, standalone active geo-replication links, and backup locations are not evaluated.'
        Version       = '1.0.0-preview'
        Category      = 'Sovereignty'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'All'
    }

    Parameter AllowedPartnerLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed partner locations'
        Description = 'The list of Azure regions where Azure SQL Database failover-group partner servers are allowed.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Sql/servers/failoverGroups' {

        Require 'partnerServers is as required' {
            Count 'partnerServers[*]' -Where {
                Arm '[replace(toLower(string(current(''Microsoft.Sql/servers/failoverGroups/partnerServers[*].location''))), '' '', '''')]' | Must -Not -BeIn (Param AllowedPartnerLocations)
            } | Must -Be 0
        }
    }

    Effect (Param Effect)
}

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