Skip to content

fix(request_condition): save state before post-create calls - #2900

Open
exitcode0 wants to merge 1 commit into
okta:masterfrom
exitcode0:fix/request-condition-orphan-on-create-failure
Open

fix(request_condition): save state before post-create calls#2900
exitcode0 wants to merge 1 commit into
okta:masterfrom
exitcode0:fix/request-condition-orphan-on-create-failure

Conversation

@exitcode0

Copy link
Copy Markdown
Contributor

Fixes #2899

Create for okta_request_condition makes up to three API calls (create POST, activate when the config sets status = "ACTIVE", and a follow-up priority PATCH), but only persisted state after all of them succeeded. If the POST created the condition and a later call failed (e.g. the transport giving up after repeated 429s in a rate-limited org), Create returned error diagnostics without ever calling resp.State.Set:

  • Terraform recorded nothing for the resource
  • the condition was left orphaned in Okta as an unmanaged INACTIVE draft
  • the next terraform apply created a duplicate condition on the app

Changes

  • Create now persists the created condition to state immediately after the create POST succeeds, before the activate call
  • After a successful activation, the saved state is refreshed so the recorded status stays accurate (and Delete deactivates correctly) if the priority PATCH afterwards fails
  • A copy of the plan model is used for the early saves so the planned status/priority values remain available to the existing follow-up logic; the successful path still ends with the same final full resp.State.Set as before

State saved during Create is preserved by Terraform even when error diagnostics are returned, so a mid-Create failure now marks the resource as tainted (replaced on the next apply) instead of orphaning it. See the plugin framework Create documentation.

Testing

  • go build ./..., go vet ./okta/services/governance/, gofmt — clean
  • Existing VCR acceptance tests replayed locally (OKTA_VCR_TF_ACC=play OKTA_VCR_CASSETTE=oie-00):
    • TestAccRequestConditionResource_Status (create with status = "ACTIVE", deactivate, reactivate — exercises both new state-save blocks) — PASS
    • TestAccRequestConditionResource_Issue2780 — PASS
    • TestAccDataSourceOktaRequestCondition_read, TestAccRequestConditionResource_basic, TestAccRequestConditionResource_Issue2510, TestAccRequestConditionResource_Priority fail identically on unmodified master (pre-existing cassette mismatches), so no regression from this change
  • No new HTTP calls are introduced, so existing cassettes replay unchanged
  • A deterministic automated test for the mid-Create failure itself isn't practical with the current VCR harness (it would need a hand-crafted cassette where the create POST succeeds and the activate call exhausts transport retries); happy to add one if maintainers can suggest a preferred seam

Notes

  • Aside for maintainers: when replaying governance-only cassettes locally, vcrManager.Cassettes() returns early if the idaas cassette directory for the test is missing, so governance tests silently run zero cassettes unless OKTA_VCR_CASSETTE is set explicitly. Not addressed in this PR.

@github-actions
github-actions Bot requested a review from dhiwakar-okta July 29, 2026 04:57
The Create function for okta_request_condition only persisted state
after every API call succeeded. When the initial POST created the
condition but a follow-up call failed (activation when the config sets
status = "ACTIVE", or the priority PATCH), Create returned error
diagnostics without ever calling resp.State.Set, so Terraform recorded
nothing. The condition was left orphaned in Okta as an unmanaged
INACTIVE draft, and the next apply created a duplicate.

Persist the created condition to state immediately after the create
POST succeeds, and refresh the saved state after successful activation,
so a mid-Create failure marks the resource as tainted instead of
orphaning it. State saved during Create is preserved by Terraform even
when error diagnostics are returned.

Fixes okta#2899
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.

okta_request_condition: activate failure during Create orphans the created condition (not saved to state, duplicate on retry)

1 participant