Provider Aliases and Multi-Region Deployments
What you'll learn: How to configure multiple instances of the same provider to manage resources in different regions or accounts simultaneously.
By default, you declare one provider per configuration—but what if you need to create resources in multiple AWS regions or separate Azure subscriptions at once? Provider aliases let you define multiple configurations of the same provider and explicitly choose which one each resource should use.
Why Provider Aliases Matter
Think of provider aliases like having multiple phone lines for different time zones. Your default provider is your primary line, but you can establish additional "lines" (aliases) to communicate with other regions or accounts without reconfiguring everything.
How Aliases Work
You define the default provider normally, then add additional provider blocks with the alias argument:
provider "aws" {
region = "us-east-1"
}
provider "aws" {
alias = "west"
region = "us-west-2"
}
Now you have two AWS providers: the default (us-east-1) and one aliased as west (us-west-2).
Assigning Resources to Aliased Providers
Use the provider meta-argument (which you've already learned) to direct specific resources to your aliased provider:
resource "aws_instance" "east_server" {
ami = "ami-12345678"
instance_type = "t2.micro"
# Uses default provider (us-east-1)
}
resource "aws_instance" "west_server" {
provider = aws.west
ami = "ami-87654321"
instance_type = "t2.micro"
# Uses aliased provider (us-west-2)
}
The syntax is provider_type.alias_name.
Common Use Cases
- Multi-region deployments for disaster recovery
- Cross-account resource management
- Global applications spanning multiple geographic locations
Key Takeaway: Provider aliases enable you to manage resources across multiple regions or accounts within a single Terraform configuration by creating named provider instances and explicitly assigning them to resources with the provider meta-argument.