Search code examples
google-cloud-platformterraformterraform-provider-gcp

How to release terraform state lock file from GCP backend when using automation for deployment


While running terraform in automation (google cloud build trigger), for some reason I have to stop or cancel the pipeline, which resulted in lock on my state file.

I understand that the process to unlock the state file is terraform force-unlock id. I do got the id, now the issue is where I have to run the said command. As I am using cloud build trigger and not cloud shell or local machine to initiate / plan / apply, thus trying to understand where to run the above command.

Terraform Backend : GCP Storage Bucket

Terraform : >= 0.14

google : = 4.18.0

Please suggest, how to release the lock file in this scenario.


Solution

  • If you don't have the access to run terraform commands but have the permissions to the Google Cloud Storage bucket that's used as the backend, you can remove .tflock file which will release the lock.

    Make sure that the lock id corresponds to the lock id shown in the error message.