Fact: AWS now allows us to break down an architecture by putting parts in different accounts. That’s the multiple account paradigm. Now it is typical to create an infrastructure over a few different accounts within the same Terraform configuration. The way to create an infrastructure component in a specific AWS account is to use a Terraform AWS provider that has credentials to that account. It’s logical. I am attempting to do that and running into a problem. When using a module, either my own or a registered Terraform module, I must pass the provider as parameter. This is where I’m running into a problem. I’m getting an error. │ Error: Invalid provider configuration reference
│
│ on use.tf line 16, in module “project_module”:
│ 16: aws = locals.account_providers[count.index]
│
You have to specify “provider.alias” assigned to the provider.
Example from:
# The default provider configuration; resources that begin with `aws_` will use
# it as the default, and it can be referenced as `aws`.
provider "aws" {
region = "us-east-1"
}
# Additional provider configuration for west coast region; resources can
# reference this as `aws.west`.
provider "aws" {
alias = "west"
region = "us-west-2"
}
resource "aws_instance" "foo" {
provider = aws.west
# ...
}
module "aws_vpc" {
source = "./aws_vpc"
providers = {
aws = aws.west
}
}