Bylaw

Gallery › General › Azure built-in policies

Allowed locations

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

This policy enables you to restrict the locations your organization can specify when deploying resources. Use to enforce your geo-compliance requirements. Excludes resource groups, Microsoft.AzureActiveDirectory/b2cDirectories, and resources that use the 'global' region.

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

Azure Policy JSONAllowedLocations_Deny.json · 63 lines
{
  "properties": {
    "displayName": "Allowed locations",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy enables you to restrict the locations your organization can specify when deploying resources. Use to enforce your geo-compliance requirements. Excludes resource groups, Microsoft.AzureActiveDirectory/b2cDirectories, and resources that use the 'global' region.",
    "metadata": {
      "version": "1.1.0",
      "category": "General"
    },
    "version": "1.1.0",
    "parameters": {
      "listOfAllowedLocations": {
        "type": "Array",
        "metadata": {
          "description": "The list of locations that can be specified when deploying resources.",
          "strongType": "location",
          "displayName": "Allowed locations"
        }
      },
      "effect": {
        "type": "String",
        "defaultValue": "Deny",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "location",
            "notIn": "[parameters('listOfAllowedLocations')]"
          },
          {
            "field": "location",
            "notEquals": "global"
          },
          {
            "field": "type",
            "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e56962a6-4747-49cd-b67b-bf8b01975c4c",
  "name": "e56962a6-4747-49cd-b67b-bf8b01975c4c"
}
Bylawe56962a6-4747-49cd-b67b-bf8b01975c4c.bylaw.ps1 · 39 lines
# Converted from AllowedLocations_Deny.json by ConvertTo-Bylaw.
Policy 'e56962a6-4747-49cd-b67b-bf8b01975c4c' {

    Properties @{
        DisplayName   = 'Allowed locations'
        Description   = 'This policy enables you to restrict the locations your organization can specify when deploying resources. Use to enforce your geo-compliance requirements. Excludes resource groups, Microsoft.AzureActiveDirectory/b2cDirectories, and resources that use the ''global'' region.'
        Version       = '1.1.0'
        Category      = 'General'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter ListOfAllowedLocations @{
        Type        = 'Array'
        DisplayName = 'Allowed locations'
        Description = 'The list of locations that can be specified when deploying resources.'
        Metadata    = [ordered]@{ strongType = 'location' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        When {
            Field location | Must -Not -BeIn (Param ListOfAllowedLocations)
            Field location | Must -Not -Be 'global'
        }

        Require 'type is Microsoft.AzureActiveDirectory/b2cDirectories' {
            Field type | Must -Be 'Microsoft.AzureActiveDirectory/b2cDirectories'
        }
    }

    Effect (Param Effect)
}

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