1
votes

As you can see below, I'm trying to pass a specific provider to a module, which then passes it as the main provider (aws = aws.some_profile) to a second, nested module.

on terraform plan I get the following error:

Error: missing provider module.module_a.provider["registry.terraform.io/hashicorp/aws"].some_profile

I must be doing somethig basic wrong or assuming the language works in a way that it doesn't. Ideas?

File structure:


├── main.tf
├── module_a
│   ├── main.tf
│   └── module_b
│       └── main.tf
└── providers.tf

main.tf (top level):

module "module_a" {
    source = "./module_a"
    providers = {
        aws.some_profile = aws.some_profile
    }
}

main.tf (inside module_a):

module "module_b" {
    source = "./module_b"
    providers = {
        aws = aws.some_profile
    }
}

main.tf (inside module b):

resource "null_resource" "null" {}

providers.tf:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 3.22.0"
    }
  }
}

provider "aws" {
    profile = "default"
    region = "us-west-2"
}

provider "aws" {
    alias = "some_profile"
    profile = "some_profile"
    region = "us-west-2"
}
1
Why do you need non default provider for your module? usually There are two main reasons to use the providers argument in the module: Using different default provider configurations for a child module. Configuring a module that requires multiple configurations of the same provider.Asri Badlah
I'm passing a non default provider so that it can be used as a default provider, as you mentioned, in the "grandchild" module.Steven Staley
Did you run terraform init before terraform apply?Asri Badlah
Yes. This response requires 15 characters so that's what this sentence is for.Steven Staley
Also terraform providers is your friend. It will show you providers that you passing to submodulesBruno Criado

1 Answers

1
votes

Ok, so after getting some answers on Reddit, it looks like although you are passing providers down to submodules you still need to declare said providers in each submodule like so:

provider "aws" { alias = "some_provider" }

And it seems like the terraform "required providers" block is only required on the very top level. However, if it isn't working you can try adding it to each submodule as well.

Hope this helps someone out.