2
votes

Issue summary: Providers not being passed to submodule

Issue description: Hello,

I'm trying to pass providers to a submodule module from the root as recommended my Hashicorp, especially now as I need to loop through the root module, using for_each. However I'm getting an error that indicates that the submodule isn't getting the provider passed down to it.

Does anyone have any guidance on what I'm doing wrong?

Thank you for your time

error:

Error: missing provider module.vpc_peering.provider["registry.terraform.io/hashicorp/aws"].requester

code: main.tf

# Requestors's credentials
provider "aws" {
  alias  = "requester"
  region = var.aws_region
  assume_role {
    role_arn = local.workspace_role_arn_requester
  }
}


# Accepter's credentials
provider "aws" {
  alias   = "accepter"
  region  = var.aws_region
  assume_role {
    role_arn = local.workspace_role_arn_accepter
  }
}

#################################################
# VPC peer from Admin to Current
#################################################
module "vpc_peering" {
  for_each  = toset(local.accepter_ids)
  source    = "./modules/peer"
  providers = {
    aws.requester = aws.requester
    aws.accepter = aws.accepter
  }

modules/peer/admin-peer.tf

module "vpc_peering_cross_account" {
  source    = "git::https://github.com/YouLend/terraform-aws-vpc-peering-multi-account?ref=aws_profile_accepter_version_0.13"
  providers = {
    aws.requester = aws.requester
    aws.accepter = aws.accepter
  }
1

1 Answers

2
votes

I got it working but for those that are experiencing the same issue, this comment on github explains what needs to be done

https://github.com/hashicorp/terraform/issues/17399#issuecomment-367342717

essentially you need an empty provider block in each module that intends to pass the providers on so in my above example this code needs to go into modules/peer/admin-peer.tf

provider "aws" {
}

provider "aws" {
  alias  = "requester"
}

provider "aws" {
  alias  = "accepter"
}