[Fix] StructToData: allow empty values through for Optional+Computed fields#2
Open
diraol wants to merge 1 commit into
Open
[Fix] StructToData: allow empty values through for Optional+Computed fields#2diraol wants to merge 1 commit into
diraol wants to merge 1 commit into
Conversation
…uted fields
Without this guard, StructToData silently dropped nil/empty API values for
*all* Optional fields — including Optional+Computed ones. This prevented
externally-set values (cluster policies, API defaults) from reaching
Terraform state, causing perpetual "(known after apply)" diffs and
breaking `lifecycle { ignore_changes }` for those fields.
Adding `!fieldSchema.Computed` preserves the existing behaviour for
Optional-only fields (server defaults are still filtered out) while
letting Optional+Computed fields write empty values to state so
Terraform can track and ignore them correctly.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
7a33342 to
f8fb5f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
StructToDataincommon/reflect_resource.gohas a gate that skips writing empty/nil API values to state forOptionalfields:This gate is correct for Optional-only fields: if the API returns a server default the user never configured, we should not pollute state with it.
However, the same gate was also firing for Optional+Computed fields — ones where the server is explicitly allowed to set the value. When the API returned an empty map or nil for such a field (e.g. a cluster policy clearing
spark_conf), the value was silently dropped, never reaching Terraform state. This caused two concrete problems:(known after apply)diffs — state never reflected the empty server value, so Terraform kept re-planning it as unknown.lifecycle { ignore_changes }not working — because the field's current server value was never written to state, the provider could not track it, and on the nextapplyit would silently revert the externally-set value back to whatever was last in state.Fix
Add
!fieldSchema.Computedto the gate condition:This preserves existing behaviour for Optional-only fields (server defaults are still filtered) while allowing Optional+Computed fields to write empty/nil values through to state.
Tests
TestStructToData_OptionalComputedEmptyMapWrittenToState— regression test: empty map for anOptional+Computedfield must reach state.TestStructToData_OptionalOnlyEmptyMapNotWrittenToState— guard test: empty map for anOptional-only field is still filtered out.Notes
This is the prerequisite central fix. Per-resource PRs (marking policy-settable fields as
Optional+Computed) will follow and depend on this change.Related: databricks#1238