Missing Terraform provider? What am I doing wrong? (Terraform v0.13.5)

Viewed 6196

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 Answers

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.

Related