Skip to content

Conversation

@jbardin
Copy link
Member

@jbardin jbardin commented Nov 7, 2025

State was using reflect.DeepEqual for comparison, but the state objects could contain values which cannot be compared using that method. Implement equality methods for each of the state objects.

These comparison are not used in any critical codepaths, but do show up in unexpected places, like backend migrations which don't appear to be needed, or incorrect exit codes when there are no changes planned.

Fixes #37406

Target Release

1.15.x

@jbardin jbardin force-pushed the jbardin/state-deep-equal branch 3 times, most recently from f14c727 to 2cc3aec Compare November 10, 2025 17:24
@github-actions
Copy link
Contributor

The equivalence tests will be updated. Please verify the changes here.

@jbardin jbardin force-pushed the jbardin/state-deep-equal branch from 2cc3aec to ae8bfe2 Compare November 10, 2025 17:42
the use of reflect.DeepEqual fails for states, because they contain
value which cannot be directly compared for equality. The Equal method
is not used much, except to aid in backend migration, so the failure
there was rarely noticed.

The failure of ManagedResourcesEqual would show up in the CLI after
Terraform reported there were no changes, by exiting with a non-zero
code because the resource states incorrectly reported as being changed.
@jbardin jbardin force-pushed the jbardin/state-deep-equal branch from ae8bfe2 to f78c64e Compare November 10, 2025 17:44
@jbardin jbardin marked this pull request as ready for review November 10, 2025 17:44
@jbardin jbardin requested a review from a team as a code owner November 10, 2025 17:44
@hashicorp hashicorp deleted a comment from github-actions bot Nov 10, 2025
@hashicorp hashicorp deleted a comment from github-actions bot Nov 10, 2025
@hashicorp hashicorp deleted a comment from github-actions bot Nov 10, 2025
@hashicorp hashicorp deleted a comment from github-actions bot Nov 10, 2025
@github-actions
Copy link
Contributor

The equivalence tests will be updated. Please verify the changes here.

@github-actions
Copy link
Contributor

The equivalence tests will be updated. Please verify the changes here.

@jbardin jbardin merged commit 64f2b5d into main Nov 10, 2025
14 of 15 checks passed
@jbardin jbardin deleted the jbardin/state-deep-equal branch November 10, 2025 20:38
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.

Wrong detailed exit code when using the refresh only option

2 participants