Partial apply and incident recovery
A failed apply is not an undo
Terraform coordinates multiple operations, potentially concurrently. An apply can stop after some changes succeed. It is not a transaction that restores every resource automatically on error. State normally records successful changes as Terraform learns them, but an interrupted provider call or failed state write can leave reality and state inconsistent. Treat an error as an incident until you know what actually changed.
SYNTHETIC incident I-17Target: catalog/test (confirmed)A: update succeeded; B: request timed out; C: not startedState: A updated; B previous revision; C unchangedB remote outcome: UNKNOWNDecision: pause writers, preserve evidence, inspect B remotely under authorizationDo not reuse prior plan or assume B was not changed.In this example, B may have been changed by the API even though Terraform did not receive confirmation. Repeating the old operation may create duplicates or make recovery harder.
Containment and evidence collection
Assign an incident owner, confirm the account/backend/workspace and coordinate a pause of new automated and manual writers. Do not forcibly interrupt a running writer merely to obtain a lock. Preserve restricted logs, the reviewed revision and plan metadata, recent backend state versions and relevant service audit records. Plans and state may contain secrets. Record the times, owners, resource addresses and remote IDs in an access-controlled incident record. Inspect actual service health and operation status using authorized read-only mechanisms. If the active target or remote outcome is unknown, escalate instead of guessing.
Evidence matrix (invented)Address A: state agrees with remote; service healthyAddress B: state older; remote operation unresolvedAddress C: not attempted; verify actual statusAction: investigate B and preserve evidence before proposing repairSeparate observed facts from assumptions; a timeout alone is not evidence that a change failed.
Inspect state and distinguish drift from repair
After authorization, with the correct target and no concurrent writer, terraform state list can inventory addresses, and terraform state show ADDRESS can inspect a specific binding. These commands can access a remote backend and reveal confidential information. A refresh-only plan proposes aligning state and root outputs with observations; it does not restore changed infrastructure. A normal plan proposes changes toward configuration. Both may call provider APIs, and reviewing a plan is not approval to apply it. In the isolated local fixture only, the following commands illustrate the difference after initialization.
terraform state listterraform plan -refresh-onlyterraform planWithout an applied fixture the state may be empty or absent. In a real incident, if a remote object exists but has no state binding, investigate ownership and supported import before proposing adoption. Never import one object into two active states. If a stale plan is detected, obtain fresh evidence and review a newly generated plan; do not force an old plan.
Locks, failed state writes and destructive surprises
Locking, where supported, coordinates state writers; a lock is not proof of healthy infrastructure. If an owner is active, coordinate and wait. If a lock remains after a confirmed termination, establish ownership and backend-specific recovery guidance before considering exceptional unlock. A failed state write may leave recovery data locally; secure it and engage the state owner. Do not blindly upload an older backup: lineage, serial, backend history and actual resource ownership must be checked. State removal stops tracking a binding rather than automatically deleting its object; it can cause duplicates on later plans. State push, state removal, forced unlock and disabling locks are not generic repairs. If the new plan proposes replacement or deletion unexpectedly, stop and check identity, schema changes, lifecycle rules and data retention.
Review and verify the recovery decision
Once evidence is complete, choose the smallest corrective change, compare state and service reality, review the new plan and get independent approval. Verify availability, data integrity, state bindings and intended configuration after the approved change. Record residual drift, open follow-ups and who may resume writers. The offline checker included with this chapter only classifies simplified incident records; it does not inspect Terraform or authorize operations.
Unknown target or active writer -> HOLDUncertain remote outcome -> INVESTIGATEFailed state persistence or stale lock -> ESCALATEUnexpected destructive change -> HOLDEvidence complete -> REVIEW_NEW_PLANNo classification authorizes applyA successful command alone is not evidence of a recovered service. Next: HCP Terraform workspaces and runs.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Partial apply and incident recovery — knowledge check
Review diagnostic and incident recovery decisions.
What can happen when apply fails after some changes succeed?
A request times out and the remote outcome is unknown. What comes next?
What is the purpose of a refresh-only plan?
A lock belongs to an active writer. What is appropriate?
What demonstrates successful incident recovery?