TERRAFORM-ASSOCIATE-003 practice question 26 of 30

[Understand Terraform Basics and CLI] When should you use the force-unlock command?

Full set: 226 questions
Answer options
A: You have a high priority change
B: Automatic unlocking failed Correct answer
C: apply failed due to a state lock
D: You see a status message that you cannot acquire the lock
Correct Answer:
B. Automatic unlocking failed
Explanation

The terraform force-unlock command is a manual intervention tool designed for exceptional circumstances where Terraform's automatic state locking mechanism fails. This typically occurs if a Terraform process is interrupted or crashes, leaving behind a "stale" lock on the state file. This stale lock prevents other Terraform operations from proceeding. The force-unlock command allows an operator to manually remove this lock after verifying that no other process is actively and legitimately modifying the state, thereby preventing potential state file corruption.

Why Incorrect

A. A change's priority is a business concern, not a technical justification for bypassing a critical safety feature like state locking, which could corrupt your state.
C. An apply failing due to a lock is a symptom, not the root cause. The lock might be held by another user's valid operation; investigation is required before forcing an unlock.
D. This message indicates normal locking behavior. The correct action is to wait for the existing operation to complete or coordinate with the team, not to forcibly break the lock. ---

References

1. HashiCorp Terraform Documentation, "State Locking": "If a command is interrupted, it may leave a stale lock file behind. You can use the force-unlock command to manually remove a stale lock file." This directly supports that the command is for situations where the automatic process (releasing the lock upon completion) has failed.

2. HashiCorp Terraform Documentation, "Command: force-unlock": "This command will remove the lock on the state for the current configuration. This will not modify your infrastructure. This is a last resort, and should only be used if you are sure that no other instance of Terraform is running." This emphasizes its use as a last resort, characteristic of a failure scenario.

3. HashiCorp Learn, "Lock and Unlock State": "In some cases, a Terraform process may exit without releasing its lock, for example if the process is killed or the machine running it crashes. In this case, you will need to manually unlock the state... To do this, run the terraform force-unlock command". This explicitly links the command's use to abnormal process termination where automatic unlocking fails.

Scroll to Top