Courseiva

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?

⚠ Common exam trap

TF-004 often tests whether candidates can distinguish a stale lock (abrupt termination) from an active lock (concurrent run) — the error message looks identical, so the discriminator is the scenario context, not the error text.

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 error shown is Terraform's state-lock error, which occurs when a lock entry exists in the backend (e.g., DynamoDB for S3) but no active process holds it. This typically happens when a previous terraform apply was killed (Ctrl+C, CI runner timeout, network drop) before Terraform could release the lock, leaving a stale lock that blocks new operations.

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.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

About these practice questions

This TF-004 question is part of Courseiva's 434-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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official HashiCorp exam blueprint

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.