Skill 6.2.1
How state locking works
Key Concepts
When a command such as plan, apply, destroy, import or state mv starts, Terraform acquires a lock from the backend and releases it when it finishes. If another process holds the lock, the command fails with an error that shows the lock ID, who holds it and when it was taken. Without locking, two simultaneous applies could each read the same state and write conflicting results, losing track of resources.
Locking depends on the backend. The local backend, Amazon S3, azurerm, gcs, consul, pg, kubernetes and HCP Terraform support it. For S3, Terraform 1.10 and later can lock natively with use_lockfile = true, which writes a .tflock object next to the state; the older DynamoDB table method (dynamodb_table) is deprecated.