// Why this matters
If you need to add an Azure region with Terraform without destroying anything, the hard part is not the new region; it is the old one. Every region-specific string in a single-region estate (resource names, map keys, DNS zones, secret paths, tool customer names) is a promise that the existing region will not be touched. Break that promise and Terraform will plan to destroy and recreate a whole regional stack: cluster, network, certificates, registry endpoints.
Multi-region is also the point at which an estate stops being a prototype. Registry replication, per-region DNS, separate state per cluster and region-aware outputs all appear at once, and each has a trap that only shows up on the second region.
This is a runbook, written from the work of extending a shared infrastructure estate from one region to a second. It complements the single-region patterns in Subscription Factory: Customer Onboarding That Starts by Minting Subscriptions and Who Deploys the Deployer? Terraform-Bootstrapped FluxCD.
// The problem
Single-region Terraform tends to hard-code the region in three ways: resources are singletons (azurerm_public_ip.entrypoint), outputs are scalars (istio_cidr_ip), and names embed a region shortcode computed at the call site. Porting such code to N regions means converting singletons to keyed collections, and every conversion changes the resource address in state. Without a plan, that is a destroy and recreate of live infrastructure.
The cloud itself adds traps. Some regions have no availability zones, so zone-redundant resources fail to create. Registry geo-replication extends every private endpoint on the registry, which collides with endpoints that pin their NIC addresses statically. A key vault certificate issued before the private endpoint exists resolves the vault to its public address and returns a firewall 403 that looks regional but is an ordering bug.
Finally, the pipelines are single-cluster too. A job that reads terraform output -raw of a scalar breaks the moment the output becomes a map, and a workloads root that reads a single cluster output cannot serve two. These are changes outside Terraform that must land in the same commit.
// The solution
The method is strict ordering plus additive-only changes. First choose and verify the region. Then allocate address space in the ledger (VNet, service, pod, plus a small range for a registry satellite network). Apply platform connectivity first, because the next layer reads its outputs. Then registry replication in two phases, then shared infrastructure, per-cluster post-apply configuration, workloads per cluster with separate state, and finally autoscaling.
For code that is not yet multi-region, port the existing shape to keyed collections before adding the new key, and write moved blocks that re-key each live resource from its bare address to ["<primary-region>"]. The acceptance gate is mechanical: the first plan after the port must show zero destroys. If it does not, a moved block is missing or mis-addressed, and you stop. Count-based resources move from index [0], not from the bare address.
Naming is made safe by deriving keys from a region shortcode in one place and requiring literals to match. Key vault names allow hyphens and storage account names do not, so the storage key and the vault key differ deliberately. Private DNS for the registry is written as explicit records rather than zone groups, so two endpoints cannot overwrite each other.
Because Terraform providers cannot be for_each'd, workloads that must be applied to N clusters are one root run N times with separate state, each pointed at its cluster via a variable and a state-suffix backend prefix; the primary keeps the empty suffix so its state path never moves. I rejected workspaces (state selection by name is easy to get wrong in CI) and a single root with aliased providers per region (every new region edits provider blocks and creates a large blast radius).
- Pick region firstzones, zone-redundant storage and the node SKU must exist
- Allocate CIDRsVNet, service and pod ranges, plus a small range for the registry satellite
- Platform connectivityper-region private DNS and peerings, applied first
- Registry phase 1disable endpoint IP pinning and apply; the plan must show in-place updates only
- Capture IPsread endpoints to map names to addresses
- Registry phase 2rewrite the pinned map, re-enable pinning, apply in the same sitting
- Gate: zero destroys gatemoved blocks re-key live resources; first plan must show no destroys
- Per-region cluster configone job per cluster with separate state
- Autoscaling and verifyregion-suffixed secrets feed the final stage
- Pick regionzones, ZRS and node SKU verified
- Allocate CIDRsVNet, service, pod, registry satellite
- Connectivityper-region DNS zone, peerings, outputs
- Registry phase 1pinning off, apply, in-place only
- Capture addressesread endpoints, map names to IPs
- Registry phase 2re-pin and apply, same sitting
- Gate: zero destroys gatemoved blocks re-key live resources
- Shared infrakeyed collections, new region keys
- Workloads and autoscalingper-cluster state, suffixed secrets
// Before you start
- An existing single- or dual-region Terraform estate with remote state, and a CIDR allocation ledger as in From Form to Running Cluster: Self-Service Team Onboarding.
- Azure CLI 2.60+ with permission to list VM SKUs in the target region and read private endpoints in the connectivity subscription.
- Terraform 1.9+ (needs
movedandimportblocks) andazurerm4.x. - GitHub Actions workflows per layer (connectivity, registry, shared infra, workloads), each runnable with plan-only mode.
- Knowledge of private endpoints, private DNS zones and your hub-and-spoke design.
// Step-by-step implementation
01 Pick the region first and verify zones, storage redundancy and the node SKU
Do this before naming anything. The region is part of every resource name, every map key, every CIDR allocation, DNS hostname, secret path and autoscaler customer name. Changing it later changes every
for_eachkey and Terraform destroys and recreates the regional stack.Check three things. The node SKU must be offered with zonal placement in the region (an empty zones list means unusable). The region must have availability zones if you deploy zone-redundant node pools, public IPs and gateways. Storage must support ZRS or GZRS if your shared storage account uses it. Legacy regions with zero zones fail all three.
02 Allocate address space and keep service ranges unique
Reserve ranges in the ledger by marking a free block used and filling assignment fields. The VNet range and the service range must not overlap any other region's. The pod range in overlay mode may be reused across regions because it is not routable outside the cluster. If you use a registry satellite VNet for private pulls, carve a small block (a /26) per region out of a reserved parent range and record the sub-allocation in the parent entry's comment.
Reserve a stable internal load balancer address for anything that clients will bootstrap against (for example a message broker), using a convention such as the second-to-last host of the subnet so it is deterministic.
03 Apply platform connectivity first: DNS zone, outputs and registry satellite
The connectivity layer must be applied before shared infra because shared infra reads its outputs by name and will fail to plan without them. For each region add a private DNS zone for internal utility names (one zone per region, not a record in a shared zone), a matching output the next layer consumes, and an entry in the registry satellite map that stamps the satellite VNet, subnet, both peerings and the DNS zone link via an existing
for_each.Never rename or repurpose an existing output. Add new region-suffixed outputs; other roots read the old ones and their plans break otherwise.
04 Replicate the container registry in two phases
Adding a replica makes the registry service extend every private endpoint on that registry with a new data member. If your endpoints pin their NIC addresses with static
ip_configuration, there is no address for the new member and the replica create fails with a replicate-private-endpoint error. You cannot pre-pin the member, because it does not exist until the replica does. So gate the pinning behind a variable and run two phases.Phase one: set pinning off, add the region to the registry's
geo_replication_locations, apply, and read the plan first. It must show in-place updates on existing endpoints; a replacement means stop. Then capture the new addresses by reading each endpoint (the NIC ipconfig names are opaque GUIDs; the endpoint's FQDN tells you which member owns which address). Phase two: rewrite the pinned map from that output, re-enable pinning and apply. Declaring addresses Azure already assigned moves nothing. Do both in one sitting: phase one re-allocates members on every endpoint of every registry in the file, so records written explicitly from the pinned map are cross-wired until phase two lands.05 Port singletons to keyed collections with moved blocks and gate on zero destroys
If the shared infra root is still single-region, port it first: convert public IPs, gateways, certificates and DNS records to
for_eachover aregion_configslocal derived from your cluster configuration, and add amovedblock for every live resource from its bare address to the primary region key. Resources gated bycountmove from[0].Then plan. The acceptance criterion is zero destroys. A destroy in that plan means a resource has no
movedblock or the address is wrong, and the correct response is to stop and fix, not to apply. Fix the pipeline in the same change: a job doingterraform output -rawof what is now a map must index it, or the primary region's pipeline breaks.06 Respect naming rules and the key vault ordering trap
Derived keys must match literal keys. The
region_configslocal derives lookup keys from the shortcode; the literal vault name in tfvars and the identity names must equal those derived strings, or the plan fails on a missing map key. The storage account key is typically not derived, so update its references by hand. Charsets differ: storage account names allow lowercase letters and digits only, so a hyphenated instance name yields an invalid name; key vault names allow hyphens. That is why the storage key is<name><sc>and the vault key<name>-<sc>.Any key vault data-plane resource (certificate, secret) must depend on the vault's private endpoint, not just the vault. The vaults deny public access and the runner reaches them over the endpoint; if the certificate is issued before the endpoint exists, the vault name resolves to its public address and you get a firewall 403 naming the runner's public IP. Only the new region hits this because the existing region's certificate predates the run, which makes it look regional.
07 Run workloads once per cluster with separate state, and add region-suffixed secrets
Providers cannot be iterated, so deploy the same workloads to N clusters by running one root N times. Parameterise the root with the cluster's location, index the remote-state outputs by that location, and template the backend prefix with a state suffix. The primary keeps the empty suffix so its state path does not move; new regions use
-<region>. In the workflow, matrix over cluster and suffix on every job that touches the cluster, including any bootstrap job that runs before the reusable call. Vault paths for non-primary clusters must be region-suffixed too, or the second run overwrites the first.The autoscaler root holds no per-cluster configuration: it resolves the cluster from Vault using a customer name. So onboarding a region to it is a region-suffixed secret set written by shared infra and a new caller job with that customer name; nothing changes in the autoscaler Terraform. Prefer an
excludelist for instance families scoped to the real constraint over a curatedincludelist, which can starve in a newer region with no capacity for the listed families.08 Expose a broker internally per region: static bootstrap, per-broker load balancers
A companion piece of regional work is exposing a TCP service such as Kafka to clients in other VNets. It cannot go through an HTTP gateway. Add a load balancer listener: the bootstrap service gets a reserved static internal address (the same second-to-last-host convention) with the internal-load-balancer annotations, and each broker gets its own internal load balancer so advertised addresses are reachable. That is one bootstrap plus one per broker (seven for a six-broker cluster).
The static bootstrap address matters because it originates in Terraform, so the DNS record and the operator's custom resource reference the same value and there is no race with the operator provisioning the service. Publish a single
bootstraprecord in the region's internal zone; clients reach brokers via the addresses returned in metadata, with no per-broker DNS. Brokers' dynamic addresses are an open item: pin them or accept re-learning after a service recreate.
// How to verify it works
- The first plan after the port shows
0 to destroy, and thejqcheck above exits 0. Moved resources appear as "has moved to" lines, not delete/create pairs. az aks list --query "[].{name:name,state:provisioningState,zones:agentPoolProfiles[0].availabilityZones}" -o jsonshows the new cluster Succeeded with zones populated.az acr replication list --registry <registry> -o tableshows all replicas Ready.dig +short <registry>.azurecr.ioanddig +short <registry>.<region>.data.azurecr.iofrom a spoke resolve to the intended hub or satellite endpoints, not another registry's.terraform output -json aks_clusters | jq keyslists both regions, and the primary region's state path in the bucket is unchanged.
// Design decisions and trade-offs
- Additive-only changes; never rename or repurpose an existing output.
- Key Vault data-plane resources depend on the private endpoint, avoiding a regional-looking 403 that is really an ordering bug.
- Explicit DNS records rather than zone groups, so two endpoints cannot overwrite each other.
- Providers cannot use for_each, so there is one root per cluster with its own state.
- Kafka design: a static reserved bootstrap address avoids an operator race; 7 internal load balancers (1 bootstrap, 6 broker).
// Pitfalls and lessons learned
- Choosing a region without zones. Zonal public IPs, gateways and node pools then fail with availability zone errors and the fix is a different region, not a flag.
- Doing registry phase one and leaving. Endpoint addresses are re-allocated across registries and explicit DNS records are cross-wired until phase two lands.
- Forgetting a
movedblock. A single missing address plans a destroy of a live gateway or certificate; treat any destroy in the first plan as a stop. - Moving count-based resources from the bare address. Count resources live at
[0]; themovedblock must start there. - Hyphens in storage account names, which are lowercase letters and digits only. Keep the storage and vault keys deliberately different.
- Sensitive-for_each errors from comparing a secret variable to an empty string. Wrap the boolean in
nonsensitive(); the boolean itself is not secret. - Curated instance family lists. They can lack on-demand capacity in a newer region; exclude only what you must.
// Frequently asked questions
How do I add a region to an existing Terraform estate without destroying resources?
Convert singletons to for_each keyed by region, add moved blocks from the old addresses to the primary key, add only new keys and outputs, and require the first plan to show zero destroys before applying.
Why does ACR geo-replication fail with a private endpoint replication error?
The replica adds a data member to every private endpoint, and statically pinned NIC addresses leave no address for it. Disable pinning, apply, capture the new addresses, then re-pin and apply.
Why can I not use for_each with Terraform providers?
Providers are configured before resources are expanded, so provider configuration cannot depend on a for_each. Run the same root once per target with separate state.
Why does my key vault certificate fail with 403 only in the new region?
The certificate was issued before the vault's private endpoint existed, so the vault name resolved publicly. Make data-plane resources depend on the private endpoint.
How do I check a region supports the VM size I need?
Run az vm list-skus -l <region> --size <sku> and read the zones from locationInfo; an empty list means no zonal placement.
// The outcome
A repeatable procedure with an explicit zero-destroy acceptance gate.
// Where to take it next
- Automate the zero-destroy assertion as a required check on every infrastructure pull request.
- Make per-registry pin gating so phase one only touches the registry being changed.
- Apply the same keyed-by-region discipline to the earlier estate in The GCP Project Factory: Folder, Project, VPC and GKE per Tenant.