AWS Provider bug with alias?


I am currently encountering a problem using the aws provider (3.42.0) with terraform version 0.12.31.

When i try to call provider with alias, terraform don’t find “region”.

Exemple :

data "cred" "aws_creds" {
  backend = "aws/preprod"

provider "aws" {
  alias      = "preprod"
  region     = "eu-west-1"
  access_key = data.cred.aws_creds.access_key
  secret_key = data.cred.aws_creds.secret_key
  token      = data.cred.aws_creds.security_token

module "instance-test01" {
  source = ""
  providers = {
    aws= aws.preprod

When apply, i have :

Error: Missing required argument

The argument "region" is required, but was not set.

And when i remove alias, aws provider work oO

It’s a bug or me doing shit?

Thx for help

Hi @cvalentin-dkt,

I think what’s happening here is that you have at least one resource in this module that doesn’t say provider = aws.preprod and so Terraform is defaulting to the default (unaliased) provider configuration for that provider. Since you have no such configuration, Terraform is behaving as if there were an empty provider "aws" {} block in your root module and then reporting that this hypothetical block is invalid because it doesn’t have region set. :confounded:

The configuration you shared here doesn’t include any resources belonging to the AWS provider so I don’t have a specific suggestion on what to update here, but I’d suggest visiting each of the resource blocks in your root module to make sure that any of them which belong to the AWS provider have provider = aws.preprod set, and thus that none of them will be referring to the implicit default provider configuration.

(This doesn’t apply to the ones in your instance-test01 module because you’ve set aws = aws.preprod at the whole module level there, and so the default AWS provider configuration inside the module is the same as the aws.preprod aliased configuration in the root module.)

The concern is that I am a “client” of the module and am not able to modify it at the current time.
I have just seen with the person responsible for the module and he tells me when the state there is not too much solution, but that they are migrating to 0.15 which should bring “configuration_aliases” and allow me to operate my Terraform.

I will wait for the migration in 0.15: /

thx for your help