Skip to content

fix(push_group): save state after deactivating during delete - #2904

Open
exitcode0 wants to merge 1 commit into
okta:masterfrom
exitcode0:fix/push-group-delete-state-divergence
Open

fix(push_group): save state after deactivating during delete#2904
exitcode0 wants to merge 1 commit into
okta:masterfrom
exitcode0:fix/push-group-delete-state-divergence

Conversation

@exitcode0

Copy link
Copy Markdown
Contributor

Fixes #2903

Delete for okta_push_group makes two mutating API calls: it deactivates the mapping (the Okta API only allows deleting an INACTIVE mapping, as the provider's own guard message says) and then deletes it. No state was written between them.

If the deactivation succeeds and the delete then fails (for example the transport giving up after repeated 429s in a rate-limited org, or a 5xx), Delete returns error diagnostics without writing state, so Terraform preserves the prior state:

  • Reality in Okta: the mapping is INACTIVE and has stopped pushing group membership to the downstream application
  • Terraform state and the next plan: status = "ACTIVE"
  • What the operator sees: failed to delete push group mapping: ..., identical to the message emitted when the deactivation itself fails, with no indication that group push has stopped

It does self-heal on the next successful apply, but silently, and only if someone re-runs.

Changes

  • After a successful deactivation, Delete records status = "INACTIVE" in the response state before attempting the delete
  • The two failure modes now have distinct error summaries: failed to deactivate push group mapping before delete and failed to delete push group mapping, and the latter states that the mapping is no longer pushing group membership downstream

State written during Delete is preserved by Terraform when error diagnostics are returned, and discarded when Delete reports no errors, so the write affects only the failure path. In internal/fwserver/server_deleteresource.go (framework v1.18.0) the response state is seeded from prior state, RemoveResource is called only when there are no error diagnostics, and resp.NewState is assigned unconditionally. See the plugin framework Delete documentation.

Testing

  • gofmt -l, go build ./..., go vet ./okta/... — clean
  • go test ./okta/... (unit, no TF_ACC) — pass
  • TestAccResourceOktaPushGroup_crud replayed locally against the existing cassette (OKTA_VCR_TF_ACC=play TF_ACC=1, classic-00) — PASS. It exercises the deactivate-then-delete path, and no new HTTP calls are introduced, so the cassette replays unchanged
  • Acceptance tests were not run against a live org; I do not have credentials for one
  • A deterministic automated test for the failure window itself isn't practical with the current VCR harness (it would need a hand-crafted cassette where the deactivation succeeds and the delete exhausts transport retries); happy to add one if maintainers can suggest a preferred seam

Notes

Delete makes two mutating API calls: it deactivates the mapping (the
Okta API only allows deleting an INACTIVE mapping) and then deletes it.
No state was written between them, so when the deactivation succeeded
and the delete then failed (for example the transport giving up after
repeated 429s in a rate-limited org), Terraform preserved the prior
state recording status = "ACTIVE" while the mapping in Okta was
INACTIVE and had stopped pushing group membership downstream.

State written during Delete is preserved when error diagnostics are
returned and discarded when Delete reports no errors, so recording the
new status between the two calls keeps state accurate on the failure
path without affecting the success path.

The two calls also reported the same error summary, which gave the
operator no way to tell "could not deactivate" from "deactivated but
could not delete". They are now distinct, and the delete failure says
that group membership is no longer being pushed downstream.
@github-actions
github-actions Bot requested a review from pranav-okta July 30, 2026 04:32
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_push_group: failed delete after successful deactivation leaves state showing ACTIVE while group push has stopped

1 participant