31

I am trying to use basic terraform commands like plan, but cannot because the terraform state is locked (see below.)

I know I am the only person or process interacting with this terraform instance, and see my name in the Who line of the lock below. I think this probably happened when I pressed Ctrl-C on a terraform prompt.

How do I unlock it?

$ terraform plan
╷   
│ Error: Error acquiring the state lock
│   
│ Error message: ConditionalCheckFailedException: The conditional request failed
│ Lock Info:
│   ID:        xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
│   Path:      xxx 
│   Operation: OperationTypePlan
│   Who:       xxx 
│   Version:   1.3.4
│   Created:   2022-11-15 19:51:21.368168706 +0000 UTC 
│   Info:           
│   
│   
│ 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.
╵   
phs
  • 10,687
  • 4
  • 58
  • 84
Amit Sharma
  • 321
  • 1
  • 3
  • 4

2 Answers2

57

You can manually unlock the state using the force-unlock command :

terraform force-unlock LOCK_ID

The lock ID is generally shown in the error message.

It may not work if your state is local and locked by a local process. If it is the case, try killing that process and retry.

Jean-Philippe Bond
  • 10,089
  • 3
  • 34
  • 60
5

To unlock the state without having to type confirmation:

terraform force-unlock -force LOCK_ID
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
AlexRak
  • 51
  • 1
  • 1