Reputation: 581
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.
╵
Upvotes: 57
Views: 113238
Reputation: 151
If your TF state file is saved on the storage account in azure or S3 bucket, you can navigate to that file and unlock as shown below (example is for azure storage location in container.)
Upvotes: 7
Reputation: 131
To unlock the state without having to type confirmation:
terraform force-unlock -force LOCK_ID
Upvotes: 13
Reputation: 10649
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.
Upvotes: 100