Skip to main content
In this lesson we cover Terraform provider aliases and how to use them with the Azure provider (azurerm). Provider aliases let you define multiple instances of the same provider within a single Terraform configuration. This is essential when you need to manage resources across multiple Azure regions, subscriptions, or isolated environments from the same codebase. Why use provider aliases? Typical scenarios include:
  • Multi-region deployment: Deploy resources to multiple Azure regions from the same Terraform configuration without duplicating code or maintaining separate projects. Use different provider aliases to target specific regions.
  • Multi-subscription / credential management: Run a single Terraform plan against multiple subscriptions or with different credentials (service principals, managed identities) — useful for hub-and-spoke and cross-subscription architectures.
  • Environment isolation: Keep production, staging, and sandbox resources separated to reduce the risk of accidental deployment into the wrong environment.
The image outlines three concepts: multi-region deployment, credential management, and isolation, each with a brief explanation related to resource distribution, credential usage, and environment separation.
Each environment, region, or subscription can have its own provider block. When resources are explicitly bound to an aliased provider, Terraform will use that instance for CRUD operations, preventing accidental resource creation in an unintended subscription or region. Example: two aliased azurerm provider instances and resources bound to them
Note the explicit bindings: provider = azurerm.weu and provider = azurerm.qc. Without these, Terraform uses the default (non-aliased) azurerm provider block, which could result in resources being deployed to the wrong subscription or region. Authentication reminder: setting subscription_id selects the target subscription, but Terraform still needs authentication credentials. Provide credentials via environment variables, a service principal, managed identity, or other supported authentication mechanisms.
Always bind resources explicitly to an aliased provider when working with multiple provider configurations. Explicit bindings prevent accidental deployments to the default provider or the wrong subscription.
Best practices and considerations When using modules that need to operate against multiple providers, pass the aliased provider into the module explicitly. Example:
This ensures the module’s resources are created in the intended subscription/region.
If resources are not bound to the correct provider alias, Terraform may create resources in the wrong subscription or region. Always verify provider bindings (and authentication) before running terraform apply.
Summary Provider aliases enable safe, maintainable multi-region and multi-subscription deployments in a single Terraform project. Use clear alias naming, explicit resource bindings, secure authentication methods, and provider-passing into modules to minimize risk and keep your infrastructure code predictable. Further reading and references

Watch Video

Practice Lab