How to unlock a tfstate file in Terraform blob storage

Teff, Simon 25 Reputation points
2023-08-29T10:46:31.7+00:00

When running Terraform Plan task in a pipeline we are getting this error:

Error: Error locking state: Error acquiring the state lock: state blob is already locked
Lock Info:
  ID:        766774a3-5af4-2b8b-a96b-b79dd8142ad8
  Path:      cont-d-dave-tfstate-adatabrickscode/$(jobPrefix)/terraform.tfstate
  Operation: OperationTypePlan
  Who:       vsts@fv-az628-644
  Version:   0.13.5
  Created:   2023-08-24 16:51:15.389045661 +0000 UTC
  Info:
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,193 questions
{count} vote

Accepted answer
  1. Sumarigo-MSFT 47,471 Reputation points Microsoft Employee Moderator
    2023-09-01T07:12:09.9733333+00:00

    @Teff, Simon I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: Unable to unlock a tfstate file in Terraform blob storage
    Error: Error acquiring the state lock: state blob is already locked

    Solution: To release a lock on a Terraform state file stored in Azure Blob Storage, perform the following actions:

    1. Navigate to the Azure Portal and locate the storage account containing your state file.
    2. Within the relevant container, locate the lock file that corresponds to your Terraform state. Typically, this file has a .tflock extension and is named after your state file.
    3. Delete this lock file to release the state lock, enabling other users to make changes to the infrastructure defined in the state file.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. niloufar kianfar 20 Reputation points
    2023-08-29T11:19:55.3133333+00:00

    To unlock a Terraform state file stored in Azure Blob Storage, follow these steps: Go to the Azure Portal and access the storage account where your state file is stored. Within the appropriate container, find the lock file associated with your Terraform state; it usually has a .tflock extension and is named based on your state file. Delete this lock file to release the state lock, allowing others to modify the infrastructure in the state file.

    0 comments No comments

  2. Juan Manuel Lainez Perez 0 Reputation points
    2024-10-19T21:05:39.78+00:00

    That's not a solution, you cannot go every time you run a pipeline and manually make a change in the blob container file. My humble opinion, the issue it's not resolved

    0 comments No comments

Your answer

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