Skip to content

fix: normalize chains JSON keys during plan phase (OKTA-1184047) - #2906

Merged
aditya-okta merged 1 commit into
masterfrom
fix/OKTA-1184047
Aug 3, 2026
Merged

fix: normalize chains JSON keys during plan phase (OKTA-1184047)#2906
aditya-okta merged 1 commit into
masterfrom
fix/OKTA-1184047

Conversation

@aditya-okta

@aditya-okta aditya-okta commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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

  • resource_okta_app_signon_policy_rules.go — new ChainsPlanModifier wired into the chains schema attribute's PlanModifiers
  • resource_okta_app_signon_policy_rules_test.go — unit test (TestChainsPlanModifier) covering sorted keys, unsorted keys, nested structures, and invalid JSON; acceptance test
    (TestAccResourceOktaAppSignOnPolicyRules_chains_misaligned_keys) with a PlanOnly idempotency step that would have failed before the fix
  • examples/resources/okta_app_signon_policy_rules/chains_misaligned_keys.tf — example config reproducing the customer scenario
  • test/fixtures/vcr/idaas/.../oie-00.yaml — VCR cassette for the acceptance test

@aditya-okta
aditya-okta marked this pull request as ready for review July 30, 2026 18:52
@github-actions
github-actions Bot requested a review from pranav-okta July 30, 2026 18:52
Comment thread okta/services/idaas/resource_okta_app_signon_policy_rules.go

@dhiwakar-okta dhiwakar-okta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments.

@aditya-okta
aditya-okta merged commit c10e91e into master Aug 3, 2026
6 checks passed
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.

2 participants