Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit passing of providers to grandchild modules not working #17399

Closed
sjauld opened this issue Feb 21, 2018 · 3 comments
Closed

Explicit passing of providers to grandchild modules not working #17399

sjauld opened this issue Feb 21, 2018 · 3 comments

Comments

@sjauld
Copy link
Contributor

sjauld commented Feb 21, 2018

Terraform Version

Terraform v0.11.3

Terraform Configuration Files

# main.tf
# The root provider
provider aws {
  region = "eu-west-1"
}

provider aws {
  region = "ap-southeast-2"
  alias  = "sydney"
}

provider aws {
  region = "us-west-2"
  alias  = "portland"
}

resource aws_ssm_parameter "root" {
  name  = "root"
  type  = "String"
  value = "derp"
}

resource aws_ssm_parameter "portland" {
  provider = "aws.portland"
  name     = "portland"
  type     = "String"
  value    = "derp"
}

resource aws_ssm_parameter "sydney" {
  provider = "aws.sydney"
  name     = "sydney"
  type     = "String"
  value    = "derp"
}

output root_arn {
  value = "${aws_ssm_parameter.root.arn}"
}

output portland_arn {
  value = "${aws_ssm_parameter.portland.arn}"
}

output sydney_arn {
  value = "${aws_ssm_parameter.sydney.arn}"
}

module "a" {
  source = "./modules/a"

  providers = {
    aws          = "aws"
    aws.portland = "aws.portland"
    aws.sydney   = "aws.sydney"
  }
}

output a_root_arn {
  value = "${module.a.root_arn}"
}

output a_portland_arn {
  value = "${module.a.portland_arn}"
}

output a_sydney_arn {
  value = "${module.a.sydney_arn}"
}

output b_root_arn {
  value = "${module.a.b_root_arn}"
}

output b_portland_arn {
  value = "${module.a.b_portland_arn}"
}

output b_sydney_arn {
  value = "${module.a.b_sydney_arn}"
}
# modules/a/main.tf
resource aws_ssm_parameter "root" {
  name  = "a.root"
  type  = "String"
  value = "derp"
}

resource aws_ssm_parameter "portland" {
  provider = "aws.portland"
  name     = "a.portland"
  type     = "String"
  value    = "derp"
}

resource aws_ssm_parameter "sydney" {
  provider = "aws.sydney"
  name     = "a.sydney"
  type     = "String"
  value    = "derp"
}

output root_arn {
  value = "${aws_ssm_parameter.root.arn}"
}

output portland_arn {
  value = "${aws_ssm_parameter.portland.arn}"
}

output sydney_arn {
  value = "${aws_ssm_parameter.sydney.arn}"
}

module "b" {
  source = "../b"

  providers = {
    aws          = "aws"
    aws.portland = "aws.portland"
    aws.sydney   = "aws.sydney"
  }
}

output b_root_arn {
  value = "${module.b.root_arn}"
}

output b_portland_arn {
  value = "${module.b.portland_arn}"
}

output b_sydney_arn {
  value = "${module.b.sydney_arn}"
}
# modules/b/main.tf
resource aws_ssm_parameter "root" {
  name  = "b.root"
  type  = "String"
  value = "derp"
}

resource aws_ssm_parameter "portland" {
  provider = "aws.portland"
  name     = "b.portland"
  type     = "String"
  value    = "derp"
}

resource aws_ssm_parameter "sydney" {
  provider = "aws.sydney"
  name     = "b.sydney"
  type     = "String"
  value    = "derp"
}

output root_arn {
  value = "${aws_ssm_parameter.root.arn}"
}

output portland_arn {
  value = "${aws_ssm_parameter.portland.arn}"
}

output sydney_arn {
  value = "${aws_ssm_parameter.sydney.arn}"
}

Debug Output

N/A

Crash Output

N/A

Expected Behavior

Providers are explicitly passed from root module to module A to module B and we can therefore create resources in module B

Actual Behavior

2018/02/21 15:26:46 [ERROR] 3 problems:

- module "b": cannot pass non-existent provider "aws"
- module "b": cannot pass non-existent provider "aws.portland"
- module "b": cannot pass non-existent provider "aws.sydney"

Steps to Reproduce

terraform init

Additional Context

There are other issues on the grandchild topic, but I believe they all related to implicit inheritance so I opened this one on explicit inheritance.

References

@jbardin
Copy link
Member

jbardin commented Feb 21, 2018

Hi @sjauld,

Sorry that this is still a bit confusing. Once we get the new configuration framework in place We're going to revisit the structure of the providers a bit more.

In the documentation for modules within providers, we mention that a configuration must have what we refer to as "proxy configuration blocks" for the providers it wants to receive. In order to make this system a bit more flexible and work with existing modules, I added the ability to allow passing a provider into a module with no corresponding block for that provider (#16619). However in order for the receiving module to pass on the provider again, it will still require a block in the configuration to reference.

What the "a" module needs is empty configuration blocks for the 3 providers, like so:

provider "aws" {
}

provider "aws" {
  alias  = "sydney"
}

provider "aws" {
  alias  = "portland"
}

Since the module is already using the providers by name, there's no additional coupling caused by requiring the empty "proxy" configuration blocks. This still can cause issues when modules want to set version constraints, which is what we're going to cover in #16835.

@sjauld
Copy link
Contributor Author

sjauld commented Feb 26, 2018

Ah, thanks @jbardin!

@sjauld sjauld closed this as completed Feb 26, 2018
@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants