Error Locking state

Hi Guys,

I am new to terraform and just installed terraform on my personal Windows machine.
I am getting output for “terraform --version” command but when i am executing terraform console then i am getting below error.

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

Please suggust, how to resolve it.

Hi @Devanshu26

Welcome to Terraform and the forums. It is a great tool once you understand it.

I don’t use Windows but the errors could indicate that another process is “holding” the lock, it can actually be a previous console or another execution of terraform plan / apply / ....

I suggest you use Process Explorer from Mark Russinovich to find out who is holding a lock:

In Linux, the lock is a file with name .terraform.tfstate.lock.info that is located in the same directory as your Terraform files. It is a hidden file, in Windows it is probably hidden as well so make sure to show hidden files.

You can use the search function in Process Explorer to find the process holding the lock, try with the directory path if you don’t know the name.

Please let us know if you find the root cause.

Thanks
Javier

Hi Javier,

Yes, there was another process that was holding terraform.
Firstly, i killed all other terraform related process and then need to execute below command to unlock state
terraform force-unlock -force [LOCK_ID]

After that check the current state of terraform by
terraform show.

Now i am able to open terraform console and it’s working fine.

Thanks
Devanshu