Warning If you wish to specify a provider configuration for the module, add an entry for aws in the required_providers block

We are using terrafrom version 0.14 and when we are trying to upgrade to 0.15 we are receiving below warning messages.

 Module module.QCVPC does not declare a provider named aws.
│ If you wish to specify a provider configuration for the module, add an entry for aws in the required_providers block
│ within the module.

We are declaring providers in separate provider.tf file

 `terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      configuration_aliases = [aws.qc, aws.dev]
    }
  }
}

provider "aws" {
  region  = "us-east-1"
}
provider "aws" {
  alias   = "qc"
  region  = "us-east-1"
}
provider "aws" {
  alias   = "dev"
  region  = "us-east-1"
}`

In the module file ec2.tf we are calling as below:

module "QCVPC " {
source = "../modules/vpc"
  providers = {
    aws = aws.qc
  }
}

Any idea on how to rectify or remove the warning messages.

Hi @chnaresh26,

The error is stating that the module does not declare a provider named aws, and is trying to direct you to add the provider requirements within the module itself.

Regarding the upgrade process, you should move to v1.0 as it is a direct continuation of the v0.15 branch. See Upgrading to Terraform v1.0 | Terraform by HashiCorp for more details, but do use the v0.15 upgrade guide as a reference for any changes in between the releases.

@jbardin
As per terraform documentation we need to declare separate provider in each module file we create is it right?
vpc.tf

provider "aws" {
region = "us-east-1"
}
module "QCVPC " {
source = "../modules/vpc"
  providers = {
    aws = aws.qc
  }
}

Same way if we have separate tf file for ec2 module again we need to declare the provider in it.

ec2.tf

provider "aws" {
region = "us-east-1"
}
module "QCec2 " {
source = "../modules/ec2"
  providers = {
    aws = aws.qc
  }
}

We have multiple aliases required in single module.tf file as below how do I need to declare the multiple providers in a module file.

vpc.tf

provider "aws" {
region = "us-east-1"
}
module "QCVPC " {
source = "../modules/vpc"
  providers = {
    aws = aws.qc
  }
}

moddule "tgwattach" {
    source = "../modules/tgwattachment"
      providers = {
    aws = aws.transit
  }
}

Please suggest

If you are wanting to use a different provider to the default, or if a module requires multiple providers of the same type then yes you’d need to include the providers section in that module.

The thing to remember is that within a directory how you split Terraform blocks between files doesn’t matter, and is really there to allow you to organise things in a sensible way. There is no technical difference between everything being in a single .tf file or each block being in a different file. The names of those files also doesn’t matter (as long as they end with a .tf).

As a result you need to make sure you don’t duplicate things. So for example in your post you seem to suggest that each file is defining the default AWS provider. Instead you should only define it once. We have the convention of putting all providers in a file called provider.tf (just our way of keeping things organised).

As mentioned earlier you need to also be including the required_providers within the module too. Again how you organise this is up to you, but you need to have a terraform block including the required_providers section.

@stuart-c @jbardin for the response and detailed explanation. Based on the documentation we need to redo our code to add providers block into all our Terraform modules folders.

Will verify and let you know how we are taking it forward.

@stuart-c @jbardin thanks for all your help we are able to upgrade to Terraform 1.1.0 with no errors and warnings and no impact to our environment.

Thanks once again for your help. I am not sure how to close this request. Please mark this as complete.