Backport of Convert variable types before applying defaults into v1.3 #32139
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.
Backport
This PR is auto-generated from #32027 to be assessed for backporting due to the inclusion of the label 1.3-backport.
WARNING automatic cherry-pick of commits failed. Commits will require human attention.
The below text is copied from the body of the original PR.
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