Terraform Lock: how to check terraform lock state?

Hello everyone!

I have a problem with the lock.

My terraform plan activates the lock. My work VPN works really bad, and the plan get stuck a lot of times with my lock.

There is a way to validate if I have a lock without running a plan or apply?

Since now, I’m running the plan again to validate if I have a lock, and to get the lock-id. Then I use “force-unlock”.
But with running the plan again, I fall again in the same problem of getting stuck by internet connection…

What do you mean by “validate if I have a lock”? The lock should only exist during the time a plan or apply is running, to prevent others from running commands until you are finished. If you get a lock and then have network issues so that the state isn’t updated or the lock released you’d need to run force-unlock as well as probably running apply again (as you might not have updated the state or finished updating things).

Hi @gaberrini

Don’t know about the lock as there are many ways to lock depending on the selected Backend.

For unreliable Internet connections I recommend using a bastion host (ssh/vnc/remote desktop) or Terraform Cloud Agents (Enterprise) or Env0 or a similar non-local solution.

What I mean is if I would be able to see the lock message without running terraform plan or apply

This is the lock message I would get with terraform plan or apply…

Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
Lock Info:
  ID:        <Lock-ID>
  Path:      <env.tfstate>
  Operation: OperationTypePlan
  Who:       <User>
  Version:   0.14.xx
  Created:   <Date>

So, the question was If I can know if I have a stuck lock without running terraform plan or apply

Hi @javierruizjimenez ,

Great thanks, I have this in mind.

The post is to confirm If I could check the lock of my local env without running plan or apply.