TF-004 Implement and maintain state Practice Question
Exhibit
Error: Error acquiring the state lock Error message: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 123456 Path: my-company-terraform-state/prod/terraform.tfstate Operation: OperationTypeApply Who: jenkins@ci Version: 1.0.0 Created: 2023-01-15 10:00:00.123456789 +0000 UTC Info: terraform apply from pipeline
Refer to the exhibit. An engineer sees this error. Which command should they run to force-unlock?
⚠ Common exam trap
The Terraform exam often tests the exact syntax of `terraform force-unlock <LOCK_ID>` versus similar-sounding commands like `terraform state unlock` or `terraform unlock`, exploiting the fact that candidates may confuse the command name or the required argument (lock ID vs. state file path).
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 123456
`terraform force-unlock <LOCK_ID>` is the exact command Terraform provides to manually release a state lock when the automatic unlocking mechanism fails (e.g., after a crash or network interruption). The lock ID is a unique identifier assigned by the backend (such as DynamoDB or Consul) when the lock was acquired, and this command bypasses the normal safety checks to force the unlock.
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 force-unlock my-company-terraform-state/prod/terraform.tfstate
Why it's wrong here
The `terraform force-unlock` command requires a specific lock ID as its argument, not the path to a Terraform state file. State locking mechanisms operate on a unique identifier generated when the lock is acquired, which must be provided to explicitly release it. Supplying a file path, even if it corresponds to the state being locked, is an incorrect syntax and will result in an error because the command expects the lock's unique ID.
- ✗
terraform unlock -id=123456
Why it's wrong here
The command `terraform unlock` is not a valid Terraform CLI subcommand. While `unlock` might intuitively seem correct, Terraform explicitly uses `force-unlock` to emphasize the potentially dangerous nature of manually releasing a state lock, especially if another operation is still active. Therefore, attempting to use `terraform unlock` will result in an "unknown command" error, regardless of the provided ID.
- ✗
terraform state unlock 123456
Why it's wrong here
The `terraform state` subcommand is primarily used for advanced state file manipulation, such as moving, removing, or listing resources within the state. However, `unlock` is not a valid operation under `terraform state`. State locking is managed as a top-level concern, directly accessible via `terraform force-unlock`, rather than being nested within the `state` management commands. This command structure is incorrect and will fail.
- ✗
terraform init -force-unlock=123456
Why it's wrong here
The `terraform init` command is responsible for initializing a working directory, which includes downloading providers and setting up backend configurations. It does not possess a `-force-unlock` flag or any functionality related to manually releasing state locks. State locking is a runtime concern handled during `terraform plan` or `terraform apply`, or explicitly managed with `terraform force-unlock`. Attempting to use this flag with `init` will result in an "unknown flag" error.
- ✓
terraform force-unlock 123456
Why this is correct
The `terraform force-unlock` command is the correct and designated method for manually releasing a Terraform state lock that has become stale or orphaned. This command requires the specific lock ID, which is typically provided in the error message when a lock prevents an operation, or can be retrieved from the backend's locking mechanism. Providing the correct lock ID ensures that only the intended lock is released, allowing subsequent Terraform operations to proceed.
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.