Provider aliases must be explicitly set with the alias attribute. Both provider blocks need aliases to be referenced separately.
aws_instance.example?provider "aws" { region = "us-east-1" alias = "east" } provider "aws" { region = "us-west-2" alias = "west" } resource "aws_instance" "example" { provider = aws.west ami = "ami-12345678" instance_type = "t2.micro" }
The resource explicitly uses provider = aws.west, which refers to the provider alias configured for us-west-2.
Centralizing provider aliases in one file and referencing them in modules improves clarity and reduces duplication.
If provider aliases point to wrong regions, resources might be created where you don't expect, potentially exposing sensitive data or violating compliance.
east and west. A child module is called without explicitly passing providers. Which provider configuration will the child module use for AWS resources?provider "aws" { region = "us-east-1" alias = "east" } provider "aws" { region = "us-west-2" alias = "west" } module "child" { source = "./child_module" # no providers passed explicitly } # Inside child_module, resource uses default provider aws
When all providers in root have aliases and no default provider is defined, child modules expecting the default provider will fail unless providers are explicitly passed.
