Scenario
You are operating a production Terraform estate. The next plan
is scheduled for the maintenance window. You run terraform plan
and see:
Error: Error acquiring the state lock
Error message: ConditionalCheckFailedException: The conditional
request failed, because the lock was acquired by another process
or the lock was force-unlocked.
Lock Info:
ID: abc123def456c7d8
Operation: OperationTypeApply
Who: engineer@mycompany.com
Version: 1.9.0
Created: 2026-08-12 14:00:00 +0000 UTC
Path: mycompany-terraform-state/production/terraform.tfstate
The lock is held by engineer@mycompany.com. The timestamp is
2026-08-12 14:00:00. The current time is 2026-08-12 16:00:00.
Your task
Determine the cause of the lock and recover. The maintenance window is in 2 hours.
Evidence to discover
# Check the lock table
aws dynamodb scan \
--table-name terraform-locks \
--select "ALL_ATTRIBUTES"
# Check the active operations
aws logs filter-log-events \
--log-group-name terraform-ci \
--start-time 2026-08-12T14:00:00Z \
--filter-pattern "engineer@mycompany.com"
Questions to answer
- Is the lock from an active operation, or is it stale?
- Is the lock holder reachable?
- Should the lock be force-unlocked?
- What is the verification procedure after force-unlock?
Recovery procedure
(Do not reveal this until the student has reasoned through the problem.)
- Verify the lock is stale. Check the timestamp. Check whether the engineer is currently running an apply.
- Contact the engineer. If they are reachable, ask them to finish or release the lock.
- If the engineer is unreachable, force-unlock.
terraform force-unlock abc123def456c7d8
- Verify the plan is empty.
terraform plan
The plan should be empty.
- Document the incident. The lock holder, the timestamp, the reason for the force-unlock, and the verification result.
Remediation
- The lock was held by a previous apply that crashed.
- The engineer is no longer active on the project.
- The force-unlock was the correct action.
- The plan is empty after the force-unlock.
- The next apply succeeds.
Prevention
- Enable DynamoDB TTL on the lock table to expire stale locks.
- Document the force-unlock procedure in the runbook.
- Train engineers to wait for the lock before force-unlocking.
- Monitor the lock table for stale entries.
What you learned
- The state lock is a coordination mechanism. The lock prevents concurrent operations.
- A stale lock is a recovery scenario. The force-unlock is the procedure.
- The verification is the plan must be empty.
- The incident is documented for the audit trail.