Skip to content

diff: don't panic on invalid keys for relevant attrs#38264

Merged
jbardin merged 2 commits intomainfrom
jbardin/path-matcher
Mar 12, 2026
Merged

diff: don't panic on invalid keys for relevant attrs#38264
jbardin merged 2 commits intomainfrom
jbardin/path-matcher

Conversation

@jbardin
Copy link
Copy Markdown
Member

@jbardin jbardin commented Mar 11, 2026

The PathMatcher used when rendering diffs assumes the caller knows the structure the path was derived from, which is isn't always correct. RelevantAttributes is derived from references to an object, which may have errors hidden by try or can functions, or the target resource structure may have changed via a schema upgrade.

Even in the case where the data may be incorrect, we can't crash when rendering the data, because the user may not be able to work around the panic with no other information about which resource contains unexpected references. This part of the rendering is only a best effort to display relevant diffs from changes outside of Terraform, and is not the place to catch any attribute path errors.

Closes #38257

jbardin added 2 commits March 11, 2026 14:12
The PathMatcher used when rendering diffs assumes the caller knows the
structure the path was derived from, which is incorrect.
RelevantAttributes is derived from references to an object, which may
have errors hidden by `try` or `can` functions, or the data may not have
been updated to match paths via targeted operations.

Even in the case where the data may be incorrect, we can't crash when
rendering the data, because the user may not be able to work around the
panic with no other information about which resource contains unexpected
references.
@jbardin jbardin added the 1.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Mar 11, 2026
@jbardin jbardin marked this pull request as ready for review March 11, 2026 20:44
@jbardin jbardin requested a review from a team as a code owner March 11, 2026 20:44
@jbardin
Copy link
Copy Markdown
Member Author

jbardin commented Mar 11, 2026

I'm still curious about how the invalid paths managed to get all the way to the rendering step, but we need a better plan to catch them. This class of panic was chased through multiple issues already (#33472, #37271, #37360, #37710, #38257). We either have paths which are incorrectly clearing the validation added in #37290, or are incorrectly serializing/deserializing them through the multiple plan and rendering formats.

@jbardin jbardin merged commit acd6a7e into main Mar 12, 2026
14 of 15 checks passed
@jbardin jbardin deleted the jbardin/path-matcher branch March 12, 2026 16:32
jbardin added a commit that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.14-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terraform crashes

2 participants