TF-004 Implement and maintain state Practice Question
Exhibit
Error: Error acquiring the state lock Lock Info: ID: 1234567890abcdef Path: terraform.tfstate Operation: OperationTypeInvalid Who: user@hostname Version: 1.0.0 Created: 2023-01-15 10:30:00.000000000 +0000 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. If you have access to the backend, you may be able to unlock it manually by running "terraform force-unlock <lock-id>".
Refer to the exhibit. A team member receives this error when running terraform apply. What is the most likely cause?
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
✓
A previous Terraform process was terminated abruptly, leaving a stale lock.
The lock info shows an operation type "OperationTypeInvalid", which typically occurs when a previous Terraform process was terminated abruptly (e.g., Ctrl+C, crash), leaving the lock in place.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The state file is corrupted and needs to be restored from backup.
Why it's wrong here
The error message 'OperationTypeInvalid' specifically refers to an issue with the lock's metadata, not the structural integrity or content of the state file itself. State file corruption would typically manifest as errors during deserialization, checksum mismatches, or unreadable file errors, indicating a problem with the state data rather than the locking mechanism. Therefore, this specific error does not suggest a corrupted state file.
- ✗
Another user is currently running terraform apply on the same state.
Why it's wrong here
If another user were legitimately holding the lock, the error message would typically indicate that the state is locked by a specific, valid operation type, such as 'terraform apply' or 'terraform plan', along with user and ID information. The 'OperationTypeInvalid' error explicitly states that the *type* of operation recorded in the lock is unrecognized or malformed. This implies the lock itself is in an inconsistent state, not actively held by a valid, ongoing process.
- ✗
The S3 bucket containing the state has been deleted.
Why it's wrong here
A deleted S3 bucket would prevent Terraform from even accessing the backend storage where the state file and lock information reside. This would result in a backend-specific error, such as 'NoSuchBucket' or 'AccessDenied', indicating a failure to connect to or locate the remote state. The current error, however, indicates an issue with the internal consistency of a lock object that Terraform was able to access.
- ✓
A previous Terraform process was terminated abruptly, leaving a stale lock.
Why this is correct
When a Terraform process terminates unexpectedly, it may fail to release the state lock gracefully, leaving behind a 'stale' lock entry in the backend. This stale lock can contain incomplete or malformed metadata, such as an 'OperationTypeInvalid' value, preventing subsequent Terraform commands from acquiring a new lock. The existing lock is improperly defined and not actively held by a running process, causing the error.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.