-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
stacks: allow dynamic provider configurations during validation #35109
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...estdata/mainbundle/test/with-single-input/provider-for-each/provider-for-each.tfstack.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
required_providers { | ||
testing = { | ||
source = "hashicorp/testing" | ||
version = "0.1.0" | ||
} | ||
} | ||
|
||
variable "provider_set" { | ||
type = set(string) | ||
default = ["a", "b"] | ||
} | ||
|
||
provider "testing" "configurations" { | ||
for_each = var.provider_set | ||
} | ||
|
||
variable "input" { | ||
type = string | ||
} | ||
|
||
component "self" { | ||
source = "../" | ||
for_each = var.provider_set | ||
|
||
providers = { | ||
testing = provider.testing.configurations[each.value] | ||
} | ||
|
||
inputs = { | ||
input = var.input | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a tricky edge in
cty
that gets us into trouble sometimes. I'm not sure if this is an example of that trouble, but I'm going to try to describe the trouble and hopefully you can decide if it matters. 😀The
null
keyword in HCL represents whatcty
would callcty.NullVal(cty.DynamicPseudotType)
-- a null value of an unknown type. That would cause this expression to returntrue
, even though I think we're not intending to acceptnull
as a provider configuration reference here:To deal with that we've typically inserted an extra check like
if result.Value.IsNull()
before doing any type checking, so that we can deal with that error case first and just treat nulls of any type as equally invalid.All of that said then: I don't think it makes sense to allow
null
here because any provider configuration slot a module declares is always required. If that's true then I'd suggest adding an extra check up at the top like I described above. If there is some reason to allow null then this might be okay, though to make that case more visible in the code I might still suggest handling it as a separate if condition since it's a common mistake to forget about the possibility of nulls when maintaining existing code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I notice below there's a comment saying that
component_instance.go
is responsible for checking whether the value isnull
, so maybe just type checking here is sufficient after all. I suggest checking that comment is actually true, though!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think I'm on the entirely wrong track here, I think your assessment that this is
cty.NullVal(cty.DynamicPseudoType)
or sth similar is right. I looked into the reference extraction and found that in theEvalScope
the provider values are from my point of view correct, it's a map of provider configurations. I couldn't find where the property access is handled / should be handled, maybe this issue is too in the weeds for me right now 🙈