Skip to content
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

Verify type assumptions when retrieving child default values #594

Merged
merged 2 commits into from
Mar 8, 2023

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Mar 3, 2023

This PR fixes the root cause of hashicorp/terraform#32752.

Essentially, when the user passes in a type that cannot be converted into one assumed by the defaults package we would see a panic when attempting to retrieve the children of the mismatch type. For example, if we are attempting to convert a list into an object (which is not possible and what is happening in the original issue) then the defaults package would panic assuming an int type should be a string as that is what the index was expecting.

This PR makes that assumption safe by verifying both the expected type of the key and the cty type expected by the defaults package match. If they don't match, the defaults package will simply not apply the defaults (by returning nil from the getChild function, as if there were no defaults to apply). As we expressly tell callers they should attempt to convert from the returned value into the concrete required type, this error would be caught then and handled nicely instead of the panic we see now.

@liamcervante liamcervante merged commit 52a64bb into hashicorp:main Mar 8, 2023
@liamcervante liamcervante deleted the liamcervante/32752 branch March 8, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants