Reputation: 431
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
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
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
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'
Upvotes: 13
Reputation: 37
Ran in same problem. I Killed all the processes from terraform that was running in background.
Upvotes: 0