Fix set diff fallback for Optional non-Computed fields without Default - #3338
Open
wlami wants to merge 2 commits into
Open
Fix set diff fallback for Optional non-Computed fields without Default#3338wlami wants to merge 2 commits into
wlami wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3338 +/- ##
==========================================
- Coverage 69.77% 69.77% -0.01%
==========================================
Files 339 339
Lines 36750 36753 +3
==========================================
+ Hits 25644 25645 +1
- Misses 9360 9363 +3
+ Partials 1746 1745 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
wlami
marked this pull request as ready for review
February 12, 2026 21:49
When a TypeSet block has an Optional (non-Computed, no Default) field
that the user doesn't specify, TF fills in the zero value ("") in the
planned state. validInputsFromPlan then fails to match plan elements
to inputs because null != "", causing makeSetDiff to fall back to a
whole-set UPDATE instead of an element-level diff.
This reproduces the noisy diff issue seen on google_compute_url_map
host_rules where adding one host rule causes every subsequent element
to appear changed.
wlami
force-pushed
the
wladi/repro-set-diff-unknown-fallback
branch
from
February 13, 2026 10:32
ae6244b to
e001ebd
Compare
… Default For Optional non-Computed string fields, SDKv2 fills "" in the planned state when the user doesn't specify the field. Treat null input as equal to "" so that set element matching succeeds and produces precise element-level diffs instead of falling back to whole-set UPDATE.
wlami
force-pushed
the
wladi/repro-set-diff-unknown-fallback
branch
from
February 13, 2026 12:19
e001ebd to
3ea346b
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.
Summary
When a
TypeSetblock contains an Optional, non-Computed field without a Default that the user doesn't specify, SDKv2 fills in the zero value (""for strings) in the planned state. The bridge'svalidInputsFromPlanfunction was failing to match these elements becausenull != "".This caused noisy whole-set
UPDATEdiffs instead of precise element-level diffs on resources likegoogle_compute_url_mapwherehost_rulehas an optionaldescriptionfield.Fix
The fix treats
nullinput as equal to the zero value for Optional non-Computed fields, allowingmatchPlanElementsToInputsto succeed and produce correct element-level diffs.Added
isZeroValuehelper that checks if a property value is the zero value for its schema type (empty string, false, 0, empty array/map).Testing
TestSDKv2DetailedDiffSetBlockOptionalUnspecifiedwith 40 test cases covering add/remove/shuffle scenariosBefore/After
Before: Adding one host rule to a URL map with 40 rules shows:
After: Shows precise element-level diff:
Fixes #3324, replaces PR #3325