Terraform / Editorial solution guide
State lock failure: establish context and the writer
Diagnose lock coordination separately from provider dependencies, credentials, and remote object access.
Read-only knowledge base · No public comments
Recognize the symptoms
Error acquiring the state lock indicates a coordination or access problem for the selected state context. It does not prove that every managed object is missing or that the provider dependency lock file is corrupt.
A previous job may have stopped unexpectedly, another authorized writer may still be active, or the backend identity or permissions may be wrong. These cases require different recovery decisions.
Understand the likely causes
- A lock protects cooperating operations on one backend/state target according to backend support. It does not coordinate unrelated states or prevent out-of-band edits to remote systems.
- .terraform.lock.hcl records provider dependency selections and integrity evidence. Its name does not mean it owns the state-writing lock, and deleting it cannot establish which job holds that lock.
Preserve the exact stage and diagnostic context
Record the operation time, approved source revision, backend type, state key or location, workspace, execution identity, and lock diagnostic without exposing secrets. Separate lock acquisition from provider installation, authorization, network access, and resource API errors. Do not rerun privileged operations repeatedly while the ownership question remains unresolved. This guide executes no Terraform command and reads no configured backend, state, or credential.
A matching workspace label is not enough
Confirm the complete intended state target through approved project and platform records. Two roots can both say default while pointing at different backend keys or paths. An unexpected lock in the wrong environment is not a reason to clear a lock in the intended one. The offline fixture checks declared identity strings only; it does not discover actual workspaces or inspect any operational storage.
requested = ('approved-backend', 'atlas/catalog', 'default')
reported = ('approved-backend', 'atlas/other', 'default')
print(f'workspace_matches={requested[2] == reported[2]}')
print(f'full_target_matches={requested == reported}')
workspace_matches=True
full_target_matches=False
The labels match but the full targets differ. These tuples are authored data, not backend responses. The result calls for context investigation, not an unlock or a state migration.
Distinguish an active writer from retained evidence
Correlate the lock owner and operation id with authorized job records, process ownership, completion status, and the responsible operator. A quiet log is not proof a writer stopped, and an old timestamp alone does not establish safe recovery. Backend outage or denied access can also prevent verification. Preserve uncertainty explicitly and involve the state owner rather than assuming any visible lock is disposable.
Recover through the backend owner and supported process
If another writer is active, coordinate or wait within the approved operation policy. If automatic unlocking failed after the owner’s operation ended, exceptional recovery still requires confirming the correct target and supported backend procedure. Force-unlocking an active operation risks conflicting writers; disabling locking does not solve ownership. State persistence failures also need reconciliation of completed remote actions. No unlock, force operation, state edit, or administrative command is supplied or executed here.
Verify the fix
After an independently authorized correction, verify the intended state target, absence of conflicting writers, normal supported lock acquisition/release, and retained state consistency. Review any partial actions before a fresh approved plan. A cleared error message alone is insufficient if the wrong state was selected or remote changes occurred during the incident.
Keep it from recurring
- Serialize cooperating writers, retain operation ids and completion evidence, document backend capabilities and owners, and distinguish state locks from dependency locks in runbooks. Protect state history and define escalation before incidents instead of making unlock the default response.