How do i safely use terraform force-unlock for stale state locks ?

Neha Kapoor 20 Reputation points
2026-10-12T06:52:37.8166667+00:00

Hi

My CI/CD pipeline is failing because of a stale Terraform state lock that is preventing infrastructure deployments. What is the safest way to use terraform force-unlock with a lock ID and how I verify the lock is no longer being used before removing it ? Many thanks

Windows for business | Windows 365 Business
0 comments No comments

1 answer

Sort by: Most helpful
  1. HLBui 13,500 Reputation points Independent Advisor
    2026-10-12T07:29:38.6+00:00

    Hi Neha Kapoor

    The safest approach is to only use terraform force-unlock <LOCK_ID> after you've confirmed that no Terraform operation is currently running against the same state. Before removing the lock, check your CI/CD pipeline history, active build agents, and any manual Terraform sessions to make sure there isn't an ongoing plan or apply that legitimately owns the lock.

    You should review the lock metadata, as it usually contains details such as who created the lock, when it was created, and the operation that was running. If the pipeline has already failed or been terminated and no active process is referencing the state, the lock can generally be considered stale.

    Once you've verified that, you can safely run the force-unlock command and then execute a terraform plan to confirm that the state remains healthy and accessible. As a best practice, try to identify why locks are being left behind in the first place, such as agent crashes, interrupted deployments, or backend connectivity issues, to prevent the problem from recurring.

    If everything is okay, don't forget to share your experience with the issue by "Accept answer". If you need more information, feel free to leave a message. We are happy to help!

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.