Skip to content

Fix set diff fallback for Optional non-Computed fields without Default - #3338

Open
wlami wants to merge 2 commits into
mainfrom
wladi/repro-set-diff-unknown-fallback
Open

Fix set diff fallback for Optional non-Computed fields without Default#3338
wlami wants to merge 2 commits into
mainfrom
wladi/repro-set-diff-unknown-fallback

Conversation

@wlami

@wlami wlami commented Feb 12, 2026

Copy link
Copy Markdown
Member

Summary

When a TypeSet block 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's validInputsFromPlan function was failing to match these elements because null != "".

This caused noisy whole-set UPDATE diffs instead of precise element-level diffs on resources like google_compute_url_map where host_rule has an optional description field.

Fix

The fix treats null input as equal to the zero value for Optional non-Computed fields, allowing matchPlanElementsToInputs to succeed and produce correct element-level diffs.

Added isZeroValue helper that checks if a property value is the zero value for its schema type (empty string, false, 0, empty array/map).

Testing

  • Added TestSDKv2DetailedDiffSetBlockOptionalUnspecified with 40 test cases covering add/remove/shuffle scenarios
  • All existing set diff tests pass

Before/After

Before: Adding one host rule to a URL map with 40 rules shows:

~ hostRules: UPDATE

After: Shows precise element-level diff:

~ hostRules: [
    + [5]: { hosts: ["new.example.com"], pathMatcher: "pm-new" }
  ]

Fixes #3324, replaces PR #3325

@codecov

codecov Bot commented Feb 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.77%. Comparing base (9ce27ac) to head (3ea346b).
⚠️ Report is 52 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wlami
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
wlami force-pushed the wladi/repro-set-diff-unknown-fallback branch from ae6244b to e001ebd Compare February 13, 2026 10:32
… 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
wlami force-pushed the wladi/repro-set-diff-unknown-fallback branch from e001ebd to 3ea346b Compare February 13, 2026 12:19
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.

Set diff falls back to whole-set UPDATE when block has Optional non-Computed field without Default

1 participant