DFdom@fradley
← ~/writing
$ cat allowed-locations-policy.md

Keep Azure in the right regions: the allowed-locations policy

Someone deploys a VM to a region on the other side of the world. Now you have data where it shouldn't be, latency you didn't plan for, and an awkward question at your next audit. Restricting which regions people can use is one of the first governance guardrails the Cloud Adoption Framework recommends, and Azure ships a built-in policy for it.

Assign the built-in "Allowed locations" policy with the regions you permit, in Terraform:

data "azurerm_subscription" "current" {}

resource "azurerm_subscription_policy_assignment" "allowed_locations" {
  name                 = "allowed-locations"
  subscription_id      = data.azurerm_subscription.current.id
  policy_definition_id = "/providers/Microsoft.Authorization/policyDefinitions/e56962a6-4747-49cd-b67b-bf8b01975c4c"

  parameters = jsonencode({
    listOfAllowedLocations = { value = ["uksouth", "ukwest"] }
  })
}

After terraform apply, Azure refuses any attempt to create a resource outside uksouth or ukwest. You don't write a custom policy.

Someone creating a resource Subscription Allowed locations UK South, UK West UK South: created UK West: created East Asia: refused
The policy checks the region of every new resource in its subscription.

The long id in the assignment is the built-in "Allowed locations" definition. To confirm it in your own tenant, look it up by name:

az policy definition list --query "[?displayName=='Allowed locations'].name" -o tsv

Later this can sit in a policy initiative (a bundle of policies assigned together) across the management-group hierarchy, with a matching rule for resource groups.

The full, runnable version is in the blog-examples repo.

discuss on linkedin → more writing