-
Notifications
You must be signed in to change notification settings - Fork 95
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
types: Prevent panics when ValueFromTerraform received nil values #208
Conversation
When getting an object under a missing (null) attribute, GetAttribute would panic instead of returning null.
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.
Hi @bluekeyes 👋 Thank you for submitting this. Fixing the panic certainly seems ideal in this situation.
In terms of implementation, the preference should likely be the following for the type implementations:
- Check for
nil
first, return null type in that situation - Perform the type check; types should ensure they align correctly upfront
- Perform the null/unknown checks
This class of panic fix should be performed in all framework defined types in the types
package and a quick nil
input unit test should be included for each type's ValueFromTerraform
such as TestObjectTypeValueFromTerraform
. The TestStateGetAttribute
unit testing addition should likely also get replicated across Config
and Plan
to try and prevent future regressions should those implementations diverge for whatever reason.
Please let us know if you have time to make these changes and thanks again for reporting this and contributing! 😄
Oh! Also feel free to create a CHANGELOG entry as well for this by creating a ```release-note:bug
types: Prevented panics when `ValueFromTerraform` received `nil` values
``` |
Also add some type tests for the container types that perform type checks but had no tests for this. This also required fixing some bad error conditions in the test code.
ValueFromTerraform
received nil
values
ValueFromTerraform
received nil
valuesThere 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.
Thanks for the review - I think I've addressed your main concerns. I did not add the nil
type check to any of the primitive types, as they don't do any explicit type checks right now, deferring to tftypes.Value.As
instead, but I could go through and do this if you'd like. It felt a bit weird without any other existing type checks.
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.
Thank you again, @bluekeyes, looks good to me 🚀
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. |
When getting an object under a missing (null) attribute,
GetAttribute
would panic instead of returning null. Also add a unit test for this case.Fixes #207.