Ad space (banner)
AD

Got the fundamentals? A structured Terraform course is a fast way to level up.

Find Terraform courses on Udemy

Affiliate link. Costs you nothing extra.

Lesson 27 / 37

What Is State Locking?

State locking stops two people from applying at the same time and corrupting the state file.

When an operation starts, Terraform takes a lock; anyone else attempting to run gets a clear "state is locked" message and waits.

Locking requires a backend that supports it — S3 with a DynamoDB table, or Terraform Cloud.

A common stumble is a lock left behind after a crashed run. force-unlock clears it, but only once you are certain nothing is still running.

In real work, locking is what makes shared infrastructure safe for a team, and it is one of the main reasons to use a remote backend.

Terraform
Try it (type this into the pseudo terminal)
terraform state list

🧑‍💻 You can type this command into the Terraform pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)