Skip to main content

How to Prevent Concurrent Terraform Applies with State Lock

Question

Two engineers and a CI pipeline sometimes run terraform apply against the same infrastructure at the same time.

Recently, the state file became inconsistent, and another run now fails with a lock error after a pipeline crashed midway. How should Terraform state be configured to prevent this, and how do you handle a stuck lock?