fix: normalize chains JSON keys during plan phase (OKTA-1184047) - #2906
Merged
Conversation
aditya-okta
force-pushed
the
fix/OKTA-1184047
branch
from
July 30, 2026 18:49
acbc843 to
02f73b8
Compare
aditya-okta
marked this pull request as ready for review
July 30, 2026 18:52
dhiwakar-okta
approved these changes
Aug 3, 2026
dhiwakar-okta
left a comment
Contributor
There was a problem hiding this comment.
Approved with comments.
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: When a user configures chains with jsonencode({...}) where HCL attribute order puts userVerification before method, Terraform preserves that source ordering in the JSON string. After apply, the
provider's Read path calls NormalizeDataJSON which re-marshals the chain through a Go map — sorting all keys alphabetically. The Framework then compares the planned value (non-alphabetical key order)
against the post-apply state value (alphabetical key order) and raises:
Error: Provider produced inconsistent result after apply
.rule[1].chains[0]: was cty.StringVal("{..."userVerification":"OPTIONAL","method":"push"...}"),
but now cty.StringVal("{..."method":"push","userVerification":"OPTIONAL"...}")
Soln: Add ChainsPlanModifier, a planmodifier.List on the chains attribute that normalizes JSON key order during the plan phase, before apply. This makes the planned value match the post-apply state value
that NormalizeDataJSON on Read already produces.
The modifier validates each chain string with json.Unmarshal and surfaces an AddAttributeError diagnostic for invalid JSON rather than silently corrupting the value to "{}".
Changes
(TestAccResourceOktaAppSignOnPolicyRules_chains_misaligned_keys) with a PlanOnly idempotency step that would have failed before the fix