Terraform-Associate-004 practice question 29 of 35

What feature stops multiple users from operating on the Terraform state at the same time?

Full set: 360 questions
Answer options
A: State locking Correct answer
B: Version control
C: Provider constraints
D: Remote backends
Correct Answer:
A. State locking
Explanation

State locking is a fundamental Terraform feature designed to prevent concurrent operations from corrupting the state file. When a command that can modify the state (e.g., terraform apply) is initiated, Terraform places a lock on the state. If another user attempts to run a conflicting command simultaneously, they will be blocked until the initial operation is complete and the lock is released. This mechanism is essential for teams working on the same infrastructure to avoid race conditions and ensure state integrity. Most, but not all, remote backends support this feature.

Why Incorrect

B. Version control: Manages changes to configuration files (.tf), not the live state file. It does not prevent simultaneous execution of Terraform commands.
C. Provider constraints: Defines which provider versions are compatible with the configuration, ensuring consistent API interactions, but does not manage state access.
D. Remote backends: A remote backend is the storage location for shared state and is a prerequisite for enabling state locking in a team, but locking is the specific feature that prevents concurrent operations.

References

1. HashiCorp Terraform Documentation, "State: Locking". The documentation states, "If supported by your backend, Terraform will lock your state for all operations that could write state. This prevents others from acquiring the lock and potentially corrupting your state."

2. HashiCorp Learn, "Manage Terraform State", Tutorial, "State Locking". This tutorial explains, "To prevent this, Terraform uses state locking. Before any operation that could write state, Terraform acquires a lock on the state file. This lock prevents any other Terraform process from acquiring the lock and writing to the state file."

3. HashiCorp Terraform Documentation, "Backends: Configuration", Section: "State Locking". This section details that "Most backends for Terraform support state locking." It clarifies that the backend provides the locking capability, but "state locking" is the name of the feature itself.

Scroll to Top