You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if bug or feature but this has been kinda frustrating. I have an API that accepts a string field, and as far as requests go, it is valid to send a payload without the field, the field as an empty string (to unset the existing value) and of course the payload with a string.
Passing a zero value such as an empty string to un-set a field is impossible to handle due to the GetOk function returning identical responses for a field set to "" and a field set to null or omitted entirely.
Am I doing this wrong or is handling values that are zero values in Go unsupported?
Placing a logger on line 546 of resource_data.go inside the func (d *ResourceData) get(addr[]string, source, getSource) getResult {} method yields the following:
Value: <nil> zero_or_schema: is nil? true // test 1 - unexpected (expected is nil to be false and result.Value to be "")
Value: <nil> zero_or_schema: is nil? true // test 2 - expected (field omitted so should be nil)
Value: stuff zero_or_schema: stuff is nil? false. // test 3 - expected (field present and has non-empty value)
Also logging output of GetOk("typeList_resource.0.strField) yields
GetOK: false // test 1 - unexpected (expected true since this field is set, but to the zero value for string)
GetOK: false // test 2 - expected (field not set so should get false for second variable)
GetOK: stuff true. // test 3 - expected (field present and got true for second variable)
Crash Output
No Crash
Expected Behavior
Expected GetOk("typeList_resource.0.strField") to return "", true for the empty string and <nil> false for the missing field
Actual Behavior
GetOk("typeList_resource.0.strField") returns "", false in both cases. Now there's no way to tell which resource had the strField set to "" and which was missing entirely.
Steps to Reproduce
terraform init
terraform apply
Additional Context
N/A
References
None
The text was updated successfully, but these errors were encountered:
After running into this and exploring the ResourceData APIs to find a workaround, we found that using GetRawConfig() allows differentiating between a field being unset and the default value.
Not sure if bug or feature but this has been kinda frustrating. I have an API that accepts a string field, and as far as requests go, it is valid to send a payload without the field, the field as an empty string (to unset the existing value) and of course the payload with a string.
Passing a zero value such as an empty string to un-set a field is impossible to handle due to the
GetOk
function returning identical responses for a field set to""
and a field set tonull
or omitted entirely.Am I doing this wrong or is handling values that are zero values in Go unsupported?
Terraform Version
Terraform Configuration Files
Debug Output
Placing a logger on line 546 of
resource_data.go
inside thefunc (d *ResourceData) get(addr[]string, source, getSource) getResult {}
method yields the following:Also logging output of
GetOk("typeList_resource.0.strField)
yieldsCrash Output
No Crash
Expected Behavior
Expected
GetOk("typeList_resource.0.strField")
to return"", true
for the empty string and<nil> false
for the missing fieldActual Behavior
GetOk("typeList_resource.0.strField")
returns"", false
in both cases. Now there's no way to tell which resource had thestrField
set to""
and which was missing entirely.Steps to Reproduce
terraform init
terraform apply
Additional Context
N/A
References
None
The text was updated successfully, but these errors were encountered: