An organization uses Terraform with AWS S3 backend and DynamoDB for state locking. During a plan, you receive an error: 'Error acquiring the state lock'. The lock information in DynamoDB shows a lock from a previous session that crashed. What is the most appropriate next step?
Trap 1: Run terraform unlock
There is no terraform unlock command.
Trap 2: Wait for the lock to expire automatically
Terraform locks do not expire automatically; they must be released manually.
Trap 3: Delete the lock item from DynamoDB table directly
While possible, it bypasses Terraform's safety checks and is not the recommended approach.
- A
Run terraform unlock
Why it fails: There is no terraform unlock command.
- B
Run terraform force-unlock with the lock ID
DynamoDB still holds the stale lock entry from the crashed session, so Terraform cannot acquire it. Passing that lock ID to terraform force-unlock deletes the orphaned record, releasing the lock without touching real infrastructure or state.
- C
Wait for the lock to expire automatically
Why it fails: Terraform locks do not expire automatically; they must be released manually.
- D
Delete the lock item from DynamoDB table directly
Why it fails: While possible, it bypasses Terraform's safety checks and is not the recommended approach.