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

Docs: "Passing Providers Explicitly" has an incorrect assertion #21923

Closed
talton-heb opened this issue Jun 27, 2019 · 6 comments
Closed

Docs: "Passing Providers Explicitly" has an incorrect assertion #21923

talton-heb opened this issue Jun 27, 2019 · 6 comments

Comments

@talton-heb
Copy link
Contributor

talton-heb commented Jun 27, 2019

Terraform Version

▶ terraform -v
Terraform v0.12.3
+ provider.aws v2.16.0

Terraform Configuration Files

main.tf

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


data "aws_region" "current" {}
data "aws_region" "other" {
  provider = "aws.other"
}


module "child" {
  source = "./child"
  providers = {
    aws = aws
    aws.other = aws.other
  }
}

child/main.tf:

provider "aws" {
  alias = "other"
}


data "aws_region" "current" {}
data "aws_region" "other" {
  provider = "aws.other"
}

resulting terraform.tfstate: (snipped for relevance)

{
  (...),
  "resources": [
    {
      "mode": "data",
      "type": "aws_region",
      "module": "module.child",
      "name": "current",
      "provider": "provider.aws",
      (...)
    },
    {
      "mode": "data",
      "type": "aws_region",
      "name": "current",
      "provider": "provider.aws",
      (...)
    },
    {
      "module": "module.child",
      "mode": "data",
      "type": "aws_region",
      "name": "other",
      "provider": "provider.aws.other",
      (...)
    },
    {
      "mode": "data",
      "type": "aws_region",
      "name": "other",
      "provider": "provider.aws.other",
      (...)
    }
  ]
}

Debug Output

N/A

Crash Output

N/A

Expected Behavior

From the last part of Passing Providers Explicitly:

At this time it is required to write an explicit proxy configuration block even for default (un-aliased) provider configurations when they will be passed via an explicit providers block:

provider "aws" {
}

If such a block is not present, the child module will behave as if it has no configurations of
this type at all, which may cause input prompts to supply any required provider
configuration arguments. This limitation will be addressed in a future version of Terraform.

As the child module did not have an explicit proxy configuration block, I would have expected something along the lines of:

  • terraform validate to fail
  • The data resource object in the state file with name = "current" and module = "module.child" to have provider = "module.child.provider.aws"
  • something to indicate the child module will behave as if it has no configurations of this type at all

Actual Behavior

  • terraform validate succeeded
  • The data resource object in the state file with name = "current" and module = "module.child" has provider = "provider.aws"
    • Implying that the implicit provider was inherited correctly despite the warning in the docs

Steps to Reproduce

  1. terraform init
  2. terraform apply
@talton-heb
Copy link
Contributor Author

NB: Nothing in the "Actual Behavior" section changes if main.tf is updated to not pass the aws provider; eg:

module "child" {
  source = "./child"
  providers = {
    aws.other = aws.other
  }
}

@jbardin
Copy link
Member

jbardin commented Jul 2, 2019

Hi @talton-heb,

It looks like you have a "proxy configuration block" in your module exactly as described in the documentation:

provider "aws" {
  alias = "other"
}

As for the un-aliased provider, the docs state "a child module automatically inherits default (un-aliased) provider configurations from its parent", which is for convenience, but also because we don't currently require providers in configuration. This means you would get the same behavior whether or not you passed the aws provider to the child module.

@jbardin jbardin closed this as completed Jul 2, 2019
@jbardin
Copy link
Member

jbardin commented Jul 2, 2019

However, I just tried a slightly different example, and it appears that you can override a default provider with an aliased provider. This was a deliberate decision on 0.11 which was to be removed in 0.12, and I have a feeling that this doc was written with the intent of changing that, but the implementation is what is failing to match.

While this should be a CLI bug, due to the requirement that it changes the configuration, we may just need to update the docs until the net major release.

@jbardin jbardin reopened this Jul 2, 2019
@talton-heb
Copy link
Contributor Author

talton-heb commented Jul 2, 2019

Later on in the docs it also says:

Once the providers argument is used in a module block, it overrides all of the default inheritance behavior, so it is necessary to enumerate mappings for all of the required providers. This is to avoid confusion and surprises that may result when mixing both implicit and explicit provider passing.

It seems weird that in the example from my second comment the default inheritance behavior is still in effect.

@mildwonkey
Copy link
Contributor

Both the functionality and documentation have been updated since this issue was opened, so I am going to close it. Please open a new issue if you continue to have a problem with terraform v0.13!

@ghost
Copy link

ghost commented Oct 13, 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 as resolved and limited conversation to collaborators Oct 13, 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

4 participants