lavoizer
lavoizer

Reputation: 431

Terrform state lock not able to release

I am getting following error message while trying to run my terraform script which uses terraform lock.

*Acquiring state lock. This may take a few moments...*

*Error: Error locking state: Error acquiring the state lock: storage: service returned error: StatusCode=409, ErrorCode=LeaseAlreadyPresent, ErrorMessage=There is already a lease present.*

I actually killed the process by using ctrl+c and now the lock is stuck. I tried terraform force-unlock 'LockID' I get the follwing error.

*Local state cannot be unlocked by another process*

Please can someone advise. thanks

Upvotes: 6

Views: 22038

Answers (4)

Duru Cynthia Udoka
Duru Cynthia Udoka

Reputation: 767

Double check and Confirm the directory you are running "terraform force-unlock 'LockID' Make sure it is inside the terraform root dir. That could be the problem

Upvotes: 1

lavoizer
lavoizer

Reputation: 431

As I was using wsl (windows subsystem linux), I had to close the wsl and restart it again. It closed all the daemon processes and also cleared the lock. At times if the state is stored remotely on Cloud, then you have to break the lease for the lock, in my case I am using Azure, I have to right click on the statefile and then click on 'break lease'

Upvotes: 6

Chris Halcrow
Chris Halcrow

Reputation: 31940

I had a similar issue when using remote state with an Azure back-end. To fix, go to the Azure storage account and container that's storing the state (look at the 'path' in the error message to determine the location of the actual state file). Click on the state file, then click 'Break lease'

enter image description here

Upvotes: 13

Manish
Manish

Reputation: 37

Ran in same problem. I Killed all the processes from terraform that was running in background.

Upvotes: 0

Related Questions