-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to force-unlock state with azurerm #17046
Comments
Also affected by this issue, any workaround? |
I was able to unlock this by going into the Azure portal and "breaking" the lease on the affected blob. It's not exactly quick :/ |
Thanks @djmitche , just did that 👍 |
Failed to unlock state - WorkaroundWhen working with Terraform remote states in Azure, sometimes the blob lease can become locked during a long running process and not released. This also occurs when you cancel an operation midway through a terraform run.
In this case, something went wrong during a previous terraform run and we don't even have a lock ID to work with. When there is already a lease present, typically it would print out a lock ID and you may us it to "force unlock" the Terraform state. The command to do this within Terraform is: terraform force-unlock <lock-id-guid> To get the lock ID, just use a random number, and it will print out the lock ID, and run
But it didn't workForce unlocking the Terraform state within an azure backend doesn't usually work, so you will have to unlock/break the blob lease manually. You will need:
Step 1:Login with your azure contributor account or service principal az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id> Step 2:container key = blob-name az storage blob lease break -b <blob-name> -c <container-name> \
--account-name <storage-account-name> --account-key <access-key> Hazzah! Unlocked!!You can see a list of blobs and if any of them have a lease/lock associated with them by running: az storage blob list -c <container-name> --account-name <storage-account-name> --account-key <access-key> |
Started seeing the same above error today with AzureRM backend. Will appreciate if you can help me towards a solution as it is a showstopper for me implementing this at my workplace. Got the latest 0.11.7 version of terraform. I am new to Go language but can still contribute to fix the defect if you can guide. |
I'm seeing the same error, but it's coming from my terraform_remote_state object. Does TF lock that state file in order to read in the data???? blob metadata "terraformlockid" was empty |
Also, it would be helpful if the timeout option worked. As I mentioned, I noticed that when reading data sources from azure using terraform_remote_state, it locks the file. If I could have a time-out where it would re-try the acquire lock, it would solve my particular case where the problem occurs when using the same data source between multiple projects and running apply on them at the same time. |
@stonefury @tombuildsstuff - my comment here on the closed #1871 may be relevant here, as it seems Terraform does indeed take locks when reading remote state as a data source. |
FTR: This also happens with Google Cloud. The workaround is to remove the state bucket from the storage. The bucket name to delete can be obtained from the local terraform state file (at |
Just thought I'd add - still an issue for AzureRm at the moment. Only workaround was to break lease, thanks @djmitche. Would be useful for a proper fix, as this could break automation solutions |
Any progress on this? This is kind of a big deal. |
The issue is still present (using latest azurerm + terraform 0.11.8). Is there any work being done by now to fix it? |
@JackTheRipper this has been fixed and is available in the Terraform 0.12 Beta |
I've still got this issue in Terraform 12.5. The odd thing is that calling force-unlock give the same message as trying to get the lock. terraform12 force-unlock -force d355e46c-3982-f1bd-7ec3-7e14e04d5e76 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The error looks like that:
Terraform Version
0.11.1
Affected Resource(s)
Terraform State ?
Expected Behavior
terraform
should unlock the state, and it should be possible to runterraform apply
again after.Actual Behavior
terraform
raises an exception and the lock is still present.Steps to Reproduce
terraform apply
Ctrl+C
terraform apply
(prints an error with the unlock id)References
Looks like this user had the same issue: https://groups.google.com/forum/#!topic/terraform-tool/we21XjC58pI
Original issue was opened on hashicorp/terraform-provider-azurerm#640
The text was updated successfully, but these errors were encountered: