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
Conversation
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 don't understand how the test case exercises the new code. The for_each
value isn't supplied, so isn't unknown. Am I missing something, or did you intend to bind an unknown value to the provider_set
input variable?
@@ -336,6 +338,10 @@ func (c *ComponentConfig) CheckProviders(ctx context.Context, phase EvalPhase) ( | |||
}) | |||
continue | |||
} | |||
} else if actualTy.Equals(cty.DynamicPseudoType) { |
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 what cty
would call cty.NullVal(cty.DynamicPseudotType)
-- a null value of an unknown type. That would cause this expression to return true
, even though I think we're not intending to accept null
as a provider configuration reference here:
providers = {
aws = null
}
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 is null
, 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 the EvalScope
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 🙈
For testing one can create a stack with a provider for_each and validate that it gets passed through correctly.
Target Release
1.8.x
Draft CHANGELOG entry
BUG FIXES