TF-004 Implement and maintain state Practice Question
Exhibit
Error: Error acquiring the state lock Error message: 2 errors occurred: * state lock was already acquired by another process * error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 12345 Path: terraform/state/default.tfstate Operation: OperationTypeApply Who: user@hostname Version: 1.5.0 Created: 2024-01-15 10:00:00 UTC Info: Terraform acquires a state lock to protect the state from being written by multiple users at the same time. Please resolve the issue and try again. $ terraform force-unlock 12345 Do you really want to force unlock the state? [y/N]: y Terraform state unlock has been successful!
Refer to the exhibit. An engineer runs 'terraform apply' and receives the lock error. After forcing an unlock, what is the most important next step?
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
✓
Check if the previous apply process is still running, and if not, proceed with the new apply.
Force-unlocking should be used with caution. The engineer must verify that the previous operation (the one holding the lock) is no longer running or has completed, otherwise unlocking could cause state corruption. The most important next step is to ensure the previous process is not active.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Check if the previous apply process is still running, and if not, proceed with the new apply.
Why this is correct
When Terraform encounters a state lock, it indicates that another operation is either still active or terminated unexpectedly, leaving the lock in place. The correct procedure is to first confirm that no legitimate Terraform process is currently modifying the state. If the previous operation has indeed completed or failed, and the lock persists, the `terraform force-unlock` command can then be used to safely release the stale lock, allowing a new `terraform apply` to proceed without risking state corruption. This ensures state integrity.
- ✗
Delete the state file and re-import resources.
Why it's wrong here
Deleting the state file is an extremely destructive action that should only be considered as a last resort in catastrophic scenarios, not for a state lock. The Terraform state file maps real-world infrastructure resources to your configuration, tracking their attributes and dependencies. Deleting it would cause Terraform to lose all knowledge of managed resources, effectively "forgetting" your infrastructure, and requiring a laborious, error-prone re-import process for every single resource, which is highly disruptive and risks resource duplication or deletion.
- ✗
Run 'terraform apply' again immediately.
Why it's wrong here
Running `terraform apply` again immediately after encountering a state lock is highly ill-advised because it directly risks state file corruption. The state lock mechanism is specifically designed to prevent concurrent operations from modifying the state file simultaneously, which could lead to an inconsistent or damaged state. Forcing another apply while a previous operation might still be active, or if the lock is genuinely held, would bypass this crucial safety mechanism and could result in resource drift, data loss, or an unrecoverable state.
- ✗
Modify the backend configuration to disable locking.
Why it's wrong here
Modifying the backend configuration to disable state locking is a dangerous practice that undermines a fundamental safety feature of Terraform. State locking prevents multiple concurrent operations from modifying the state file simultaneously, which is critical for maintaining state consistency, especially in collaborative environments. Disabling it would expose your infrastructure to race conditions, potential state corruption, and unpredictable resource management behavior, making it an unacceptable workaround rather than a solution to a temporary lock.
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.