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:
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.
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.