Yash Verma / Cloud runbook

Terraform state is locked

A plan or apply fails with "Error acquiring the state lock". All playbooks.

  1. Read the error: it shows the lock ID, who holds it and when it was taken. If a CI job or a colleague is mid-apply, wait for it.

  2. Only when you are sure the run that holds it has died, release the lock with that ID.

    Force unlock state file

    Manually removes a lock on the state file if a previous pipeline crashed.

    Caution. Only when you are sure no other run holds the lock. Two runs writing the same state can corrupt it.

    terraform force-unlock <lock-id>

    state, lock, debug

  3. Run a fresh plan to confirm the state matches what you expect before you apply anything.

    Generate and save a plan

    Generates an execution plan to a file.

    terraform plan -out=tfplan

    plan, review