Skip to content
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

How to get the lock id? #17535

Closed
robsonpeixoto opened this issue Mar 8, 2018 · 9 comments
Closed

How to get the lock id? #17535

robsonpeixoto opened this issue Mar 8, 2018 · 9 comments

Comments

@robsonpeixoto
Copy link

Terraform Version

$ terraform version
Terraform v0.11.3
+ provider.azurerm v1.2.0

I need to force a unlock, but how to get the lock id?

$ terraform destroy
Acquiring state lock. This may take a few moments...

Error: Error locking state: Error acquiring the state lock: 2 error(s) occurred:

* storage: service returned error: StatusCode=409, ErrorCode=LeaseAlreadyPresent, ErrorMessage=There is already a lease present.
RequestId:132435b7-101e-004b-552e-b732a8000000
Time:2018-03-08T22:41:18.7452012Z, RequestInitiated=Thu, 08 Mar 2018 22:41:18 GMT, RequestId=132435b7-101e-004b-552e-b732a8000000, API Version=2016-05-31, QueryParameterName=, QueryParameterValue=
* blob metadata "terraformlockid" was empty

Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.
~> terraform force-unlock 132435b7-101e-004b-552e-b732a8000000
Do you really want to force-unlock?
  Terraform will remove the lock on the remote state.
  This will allow local Terraform commands to modify this state, even though it
  may be still be in use. Only 'yes' will be accepted to confirm.

  Enter a value: yes

Failed to unlock state: failed to retrieve lock info: blob metadata "terraformlockid" was empty
@robsonpeixoto robsonpeixoto changed the title How to get the lock id? [question] How to get the lock id? Mar 8, 2018
@jbardin
Copy link
Member

jbardin commented Mar 8, 2018

Hi @robsonpeixoto,

Thanks for filing this. For most backends, the error message would indicate exactly what the lock ID was. In this case, the metadata blob is missing altogether, so terraform never gets to print the lock information. I believe, as you've guessed, that the lock ID is also the lease RequestID, but in your case the failure to fetch the lock info causes the unlock to abort before the lease can be released.

Unfortunately I'm not really familiar with azurerm, but there might be some method through the web console or cli to release the lease on the state blob itself.

@tombuildsstuff, do you what the easiest workaround for this might be, until I get a patch into the backend?

@tombuildsstuff
Copy link
Contributor

hey @robsonpeixoto

So there's a workaround for this issue in this comment - but this can either be done using the Azure CLI or the Azure Blob Storage Explorer, by releasing the lock on the file.

There's a separate task to update the AzureRM Backend to workaround this issue which is being tracked in #17046.

@robsonpeixoto robsonpeixoto changed the title [question] How to get the lock id? How to get the lock id? Mar 9, 2018
@robsonpeixoto
Copy link
Author

Thanks @tombuildsstuff.

@apparentlymart
Copy link
Contributor

It sounds like the other discussions Tom linked have workarounds to get you what you need here in the short term, @robsonpeixoto, so I'm going to close this issue just to consolidate the discussion over in #17046.

Sorry for the weird behavior here, and thanks for reporting it!

@davehowell
Copy link

This is a true story! It happened to me a friend of a friend of mine.

I have a project that spans both AWS and GCP, the tfstate is stored on GCP in a cloud storage bucket (p.s. that is so much nicer than the AWS solution involving dynamoDB).

My environment requires temporary credentials & token for AWS. I've noticed that when I run terraform apply, if I don't currently hold valid AWS credentials, then it takes a reeeaaally long time to time out. A really long time. It's kind of my fault that it fails, because I forget to refresh my AWS credentials, but how long it takes to time-out is suuuper annoying. As a side note, is there anything I can do to make it fail faster? Probably a question for the AWS Provider side, anyhow.

My hokey-pokey jig is to cancel the terraform apply with control+C a couple times, then refresh my credentials and then terraform apply again. Previously I had the tfstate locally, and didn't see any lock issues, I guess there's no locking for local state- what would be the point of locking-for-one. With state now on GCP, it's failed to unlock.

It's probably the second time I hit control+C that is the cause of this problem; terraform is even kindly warning me that the first time it shuts down gracefully (but I am too impatient for that) and the second time just exits abruptly. It's the correct behaviour, P.E.B.K.A.C.

Move along nothing to see.

@einSelbst
Copy link

I had that same problem with AWS. Looking into the dynamo db table to see the ID there was working, but I guess when I'm there already I can also just delete the entry right there!?

@aryannava
Copy link

rename your terraform.tfstate file. Looks like it got corrupted
I got an alike problem and I renamed the file

Error: Error locking state: Error acquiring the state lock: open terraform.tfstate: permission denied

Terraform acquires a state lock to protect the state from being written

by multiple users at the same time. Please resolve the issue above and try

again. For most commands, you can disable locking with the "-lock=false"

flag, but this is not recommended.

aryan@aryan-VirtualBox:~/docker$ ls

main.tf terraform.tfstate

aryan@aryan-VirtualBox:~/docker$ ll

total 20

drwxr-xr-x 3 aryan aryan 4096 May 7 14:07 ./

drwxr-xr-x 21 aryan aryan 4096 May 7 13:57 ../

-rw-r--r-- 1 aryan aryan 279 May 7 13:57 main.tf

drwxr-xr-x 3 aryan aryan 4096 May 7 12:26 .terraform/

-rw-r--r-- 1 root root 1161 May 7 12:37 terraform.tfstate

aryan@aryan-VirtualBox:~/docker$ ls .terraform/

plugins

aryan@aryan-VirtualBox:~/docker$ less terraform.tfstate

aryan@aryan-VirtualBox:~/docker$ mv terraform.tfstate old_terraform.tfstate

@i255d
Copy link

i255d commented May 9, 2019

I ran this from a command prompt in PowerShell and it unlocked my file: $ Get-Process terraform | Stop-Process -force

@ghost
Copy link

ghost commented Jul 26, 2019

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.

@ghost ghost locked and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants