-
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
Convert variable types before applying defaults #32027
Conversation
I'm not sure this change is valid, but I'm also not sure it's invalid. We originally applied defaults before converting type in part to allow us to distinguish between missing object attributes and attributes with However, you should be able to assign a |
It breaks because when it arrives in the I did have a look at going into go-cty and fixing the convert function to allow this. Here's a test case I wrote in go-cty that matches what the test case here is essentially trying to do: zclconf/go-cty#139. |
…te/convert-before-defaults
I've reverted the change I had to make to the other test, which means the tests are now going to report as failing. But once the following PRs are merged into go-cty and released this test will start passing again: |
This is ready for review! |
Co-authored-by: alisdair <[email protected]>
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
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. |
Fixes #31978
Currently Terraform attempts to apply defaults in variables before calling go-cty to convert the variables into their actual concrete types. This can lead to a situation where HCL cannot apply the defaults because of a type incompatibility and then panics and crashes Terraform (#31978). It's kind of impossible to recover from or predict this situation without modifying the HCL public functions (eg. make the panic return an error, or add a new function like
CheckCanApplyDefaults
). We can't do this check with go-cty because as far as go-cty is concerned these are perfectly valid conversions. Note, that HCL and go-cty disagree here about what is or what isn't a valid type conversion.This PR switches the order of these operations. We now go through go-cty to convert to the concrete type first, then when we call the apply defaults function the types are guaranteed to match and HCL doesn't need to worry about any kind of conversions.
This change requires an upstream fix in go-cty, so go-cty is updated as part of this change.
Target Release
1.3.4
Draft CHANGELOG entry
BUG FIXES