Hi All,
I am getting below warning on passing explicit providers in module :
Warning: Reference to undefined provider
│
│ on managed_kafka_redis.tf line 30, in module "create_msk_ap-southeast-3":
│ 30: aws = aws.ap-southeast-3
│
│ There is no explicit declaration for local provider name "aws" in module.create_msk_ap-southeast-3, so Terraform is assuming you mean to pass a configuration for
│ "hashicorp/aws".
│
│ If you also control the child module, add a required_providers entry named "aws" with the source address "hashicorp/aws".
Files structure:
- providers.tf
- main.tf
-variables.tf
-modules
-sampleModule.tf
providers.tf
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.11.0"
configuration_aliases = [ aws.us-east-1]
}
}
provider "aws" {
region = var.aws_region
access_key = var.aws_access_key_id
secret_key = var.aws_secret_key
}
provider "aws" {
region = "us-east-1"
access_key = var.aws_access_key_id
secret_key = var.aws_secret_key
alias = "us-east-1"
}
}
main.tf
module "create_resource" {
source = "./modules"
for_each = {for x in var.sampleInput: x=> x }
}
module "create_resource_us-east" {
source = "./modules"
providers = {
aws = aws.us-east-1
}
for_each = {for x in var.sampleInput: x=> x }
}
As the module is having for_each
loop, terraform does not allows specifying providers configuration inside the module. Ref- Providers Within Modules - Configuration Language | Terraform | HashiCorp Developer
I had verified the code and appropriate provider configuration is getting passed to each of the module.
But I am not sure why I am getting the warning Reference to undefined provider
and how to resolve it. Any insights on this?