Back to Devoured - May 25, 2026
DEVOURED
Deploying to Multiple Azure Subscriptions with Terraform Provider Aliases

Deploying to Multiple Azure Subscriptions with Terraform Provider Aliases

DevOps Techielass
Sarah Lean demonstrates how to deploy resources across multiple Azure subscriptions from a single Terraform project using provider aliases and a unified state file.
What: Terraform's provider aliases feature allows defining multiple instances of the `azurerm` provider, each configured for a different Azure subscription ID (e.g., `sub1`, `sub2`, `sub3`), enabling a single Terraform project to manage resources across development, staging, and production environments. Resources are explicitly linked to an aliased provider using the `provider` meta-argument.
Why it matters: This approach simplifies Infrastructure-as-Code management for organizations with multi-subscription Azure environments, reducing the overhead of maintaining separate Terraform projects and state files for each subscription, which improves consistency and reduces operational complexity.
Takeaway: If managing multiple Azure subscriptions with Terraform, consider adopting provider aliases to consolidate your infrastructure code into a single project, simplifying deployment and state management.
Deep dive
  • By default, Terraform's azurerm provider targets a single Azure subscription.* Organizations often use separate subscriptions for different environments like dev, staging, prod.* Without aliases, this typically means separate Terraform projects and state files per subscription.* Terraform provider aliases allow declaring multiple instances of the same provider within one project.* Each instance is configured with a unique alias and a specific subscription_id.* The article provides a step-by-step guide with code examples for variables.tf, providers.tf, and main.tf.* Resources are "pinned" to a specific provider instance using the provider = azurerm.alias_name meta-argument.* This enables a single terraform plan and terraform apply to manage resources across all aliased subscriptions.* The approach improves consistency, reduces configuration drift, and centralizes state management.
Decoder
  • Terraform provider aliases: A Terraform feature allowing multiple configurations of the same provider within a single project, differentiated by an alias argument, enabling management of resources across different environments or accounts of the same cloud provider.* azurerm provider: The official Terraform provider for managing resources in Microsoft Azure.* provider meta-argument: A Terraform argument used within a resource block to explicitly specify which provider configuration (including aliased ones) should be used for that resource.* Azure subscription: A logical container for Azure services, managed by an Azure account, often used to separate billing, environments, or organizational units.
Original article

Full article content is not available for inline reading.

Read the original article →

Explore all 62 articles in today's digest

Fresh dev news, AI-digested daily. Never miss a trend at devoured.fyi