Courseiva
Use the core Terraform workflowhardMultiple ChoiceObjective-mapped

TF-004 Use the core Terraform workflow Practice Question

A team uses Terraform with remote state in an S3 backend and DynamoDB for state locking. A user runs 'terraform apply' and receives the error: 'Error acquiring the state lock'. The lock info shows a lock ID and caller. What is the best immediate course of action?

⚠ Common exam trap

HashiCorp often tests the misconception that deleting the state file or DynamoDB item is a valid fix, but the trap here is that candidates confuse state file management with lock management, leading them to choose destructive actions instead of the proper unlock command.

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 another Terraform process is running; if not, use 'terraform force-unlock' with the lock ID.

The error indicates a state lock is held, typically by another Terraform process or a stale lock. The best immediate course is to verify no other process is running (e.g., via 'ps' or task manager), then use 'terraform force-unlock -lock-id=<LOCK_ID>' to release the lock. This is the safe, documented procedure that preserves the state file and DynamoDB lock table integrity.

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 another Terraform process is running; if not, use 'terraform force-unlock' with the lock ID.

    Why this is correct

    This is the correct and safest approach. Before attempting to unlock, it's crucial to confirm that no legitimate Terraform process is actively holding the lock, which could lead to state corruption if prematurely released. If the lock is indeed orphaned due to a crashed or terminated process, `terraform force-unlock <LOCK_ID>` explicitly releases it, allowing subsequent operations to proceed without manual intervention in the backend.

  • Delete the state file from S3 and re-run apply.

    Why it's wrong here

    Deleting the `terraform.tfstate` file from the S3 backend is highly destructive and should never be done as a solution for a locked state. This action would cause Terraform to lose all knowledge of the infrastructure it previously managed, effectively "forgetting" existing resources. A subsequent `terraform apply` would then attempt to create new resources, potentially duplicating or even destroying existing infrastructure if not handled with extreme care, leading to significant operational disruption.

  • Manually delete the DynamoDB lock table item.

    Why it's wrong here

    Directly manipulating the DynamoDB lock table item, while technically possible, is strongly discouraged and considered an anti-pattern. This bypasses Terraform's internal state management and validation, increasing the risk of introducing inconsistencies between the actual lock status and what Terraform perceives. Such manual intervention is error-prone and can lead to more complex issues, whereas `terraform force-unlock` is the officially supported and safer method for releasing orphaned locks.

  • Wait for 15 minutes and re-run apply.

    Why it's wrong here

    Waiting for an arbitrary period like 15 minutes will not resolve an orphaned Terraform state lock. Terraform's state locking mechanism, typically implemented via DynamoDB for S3 backends, is designed for persistence; a lock remains active until the Terraform process that acquired it successfully completes and releases it, or until it is explicitly `force-unlocked`. There is no automatic timeout or expiration for these locks, meaning an orphaned lock will persist indefinitely, blocking all subsequent operations.

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 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 →

How Courseiva writes practice questions · Editorial policy

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.