-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 provider block non-default only #25317
Conversation
we only need to pass the non-default provider(s) to a child module, while the default too is passed, current statement states all providers need to be passed explicitly which is bit confusing as there is no clarity on the default provider also being passed.
Codecov Report
|
Hi @erbalaji! Thanks for working on this. This paragraph is intending to say that if you set provider "aws" {
# ...
}
provider "aws" {
alias = "example"
# ...
}
module "example" {
source = "./modules/example"
} With the above, the However, the situation changes if we explicitly pass the aliased configuration: module "example" {
source = "./modules/example"
providers = {
aws.other = aws.example
}
} This means that there would now be no default # The child module must have a "proxy provider configuration" to declare
# that it is expecting to be passed an aliased configuration called "other".
provider "aws" {
alias = "other"
}
resource "aws_instance" "example" {
# All AWS provider resources must be bound to the "other" aliased
# configuration, because there is no default configuration defined
# in this module.
provider = aws.other
} If the module needs both a default and an aliased provider configuration then the call must specify both, and that is what the paragraph you updated here was intending to say: module "example" {
source = "./modules/example"
providers = {
aws = aws
aws.other = aws.example
}
} With the above, it's once again possible to have resources in the module that bind automatically to the default (unaliased) provider configuration, because the I've written all this out here because your opening this PR tells me that the current documentation isn't clear about something, but the change you've proposed here doesn't seem to me to describe the intended behavior of Terraform and so I'd like to learn more about what situation you encountered that led you to see this statement as incorrect, and then we can see about either clarifying the documentation or possibly correcting a bug in Terraform, depending on what exactly you saw. |
Hi All - checking in on the status of this as it's about a year old now. Is it still relevant, or should we close it out? Thank you! |
@apparentlymart, thank you for the explanation. It matches up with the behavior I would expect given this quote from the documentation:
The problem is, it doesn't seem to be true! I set up the following two files, mirroring your example: main.tf provider "aws" {
region = "us-west-2"
}
provider "aws" {
alias = "other"
region = "us-east-2"
}
module "example" {
source = "./example"
providers = {
aws.other = aws.other
}
} In this example/main.tf terraform {
required_providers {
aws = {
source = "hashicorp/aws"
configuration_aliases = [aws.other]
}
}
}
resource "aws_sns_topic" "default" {
name = "example-default"
}
resource "aws_sns_topic" "other" {
provider = aws.other
name = "example-other"
} In the
But this works just fine, creating two topics in two different regions. The upshot is that I believe the default inheritance behavior does continue to operate, even when the Of course, it's been a few years since this PR was opened, and things have changed (for example, "proxy provider configurations" are no longer used). I'm happy to open a new issue rather than revive this stale PR if that would be preferable. |
@ravron Can you please open a new PR? I am going to close this one due to it being fairly old, we can at least triage your new PR. Thanks! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
we only need to pass the non-default provider(s) to a child module, while the default too is passed, current statement states all providers need to be passed explicitly which is bit confusing as there is no clarity on the default provider also being passed.