TF-004 Implement and maintain state Practice Question
During a deployment, a user runs `terraform apply` but the command fails because the state lock cannot be acquired. They suspect the lock was released after the previous `apply` but is still held. What command can they use to force unlock the state?
⚠ Common exam trap
The Terraform exam often tests the exact command syntax, so candidates may confuse `terraform force-unlock` with non-existent commands like `terraform state unlock` or `terraform break-lock`, or misuse `terraform init -force-copy` which serves a completely different purpose.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
`terraform force-unlock <lock_id>`
When Terraform cannot acquire a state lock because it was not properly released (e.g., after a crash or interrupted apply), the `force-unlock` command is the only built-in way to manually break the lock. You must provide the lock ID (obtained from the error message or backend) to override the lock, which is stored in the backend (e.g., DynamoDB, Consul) and prevents concurrent modifications. This command is designed for recovery scenarios where the lock holder is known to be dead.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
`terraform init -force-copy`
Why it's wrong here
The `terraform init` command initializes a working directory, configuring backends and providers. The `-force-copy` flag is specifically used in conjunction with `terraform init -migrate-state` to compel a copy of the state file during a backend migration, even if a move would typically occur. This flag has no function related to releasing or managing state locks, which are handled by distinct commands.
- ✓
`terraform force-unlock <lock_id>`
Why this is correct
This command is the correct and designated mechanism for manually releasing a stuck or orphaned Terraform state lock. When a Terraform operation is interrupted, the state lock might persist, preventing subsequent operations. By providing the unique `<lock_id>`, this command allows an administrator to force the release of the specific lock, enabling further infrastructure changes to proceed safely. This is an essential recovery tool for maintaining operational continuity.
- ✗
`terraform state unlock`
Why it's wrong here
While `terraform state` is a valid subcommand for various state management operations, `unlock` is not a recognized action directly under it. Terraform's CLI structure requires specific commands for managing state locks, and `terraform state unlock` is syntactically incorrect. Attempting to execute this command would result in an error, indicating an unknown or unsupported subcommand for state manipulation.
- ✗
`terraform break-lock`
Why it's wrong here
The command `terraform break-lock` is not a valid or recognized command within the Terraform CLI. Terraform's command-line interface follows a predefined structure of commands and subcommands for managing infrastructure. Using an undefined command like `break-lock` will simply result in an 'Unknown command' error, as it does not correspond to any functionality for state lock management or other Terraform operations.
Go deeper
Related to this question
About these practice questions
Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.