How do you structure Terraform for multiple Azure environments and subscriptions?
AdvancedConceptAzure DevOps, Bicep and Terraform
Answer
- Reusable modules (network, aks, acr, keyvault), versioned via git tags or a private registry.
- One root configuration per environment (or per environment and region) with its own state key and subscription, for example
envs/dev,envs/prod. - Provider aliases when one configuration must touch two subscriptions (spoke and hub for peering, DNS zone in a connectivity subscription).
- Separate state for long-lived foundations (network, identity) and fast-moving app infrastructure, linked with
terraform_remote_stateor data sources.
Workspaces are fine for identical, ephemeral copies; for prod vs dev with different sizes and approvals, separate roots are clearer.
More on Azure DevOps, Bicep and Terraform
What services make up Azure DevOps?BeginnerWhat are branch policies in Azure Repos?BeginnerExplain the YAML pipeline structure in Azure Pipelines.BeginnerWhat are service connections and how should they authenticate?IntermediateWhat are environments in Azure Pipelines?IntermediateWhat deployment strategies do deployment jobs support?Intermediate