Friday, November 24, 2023
HomeSoftware Engineering Error buying the state lock in Terraform

[Solved] Error buying the state lock in Terraform

When you’ve got been handed the Buying state lock error message about ConditionalCheckFailedException: The conditional request then you’ve gotten 2 choices for fixing it!

The error appears to be like one thing like this:

Buying state lock. This may occasionally take just a few moments...
│ Error: Error buying the state lock
│ Error message: ConditionalCheckFailedException: The conditional request
│ failed
│ Lock Data:
│   ID:        3324a6cb-7401-3194-d650-fxxxxxx3864
│   Path:      xxxx-terraformstate-nonprod/env:/xxxx/terraform.tfstate
│   Operation: OperationTypeApply
│   Who:       [email protected]
│   Model:   1.0.4
│   Created:   2021-11-29 21:00:37.652114035 +0000 UTC
│   Data:
│ Terraform acquires a state lock to guard the state from being written
│ by a number of customers on the similar time. Please resolve the difficulty above and take a look at
│ once more. For many instructions, you may disable locking with the "-lock=false"
│ flag, however this isn't beneficial.

There are 3 doable methods to repair this

Briefly, you wish to delete the lock related. That is achieved by forcing an unlock.

You possibly can drive unlock the state utilizing the next:

terraform force-unlock -force 3324a6cb-7401-3194-d650-fxxxxxx3864

Possibility 2: Relaunch the Plan

You possibly can run the plan once more with a -lock=false as following:

terraform plan -lock=false ...

Possibility 3: Be sure to use the precise profile!

Typically every thing appears appropriate, nevertheless it seems you’re utilizing a distinct profile!


Drive Unlock nonetheless not working?

Typically you may get one other error when attempting to drive unlock this:
Didn't unlock state: did not retrieve lock information: surprising finish of JSON enter

This normally means that you’re within the flawed workspace.

View all workspaces accessible: terraform workspace record

Change to a workspace: terraform workspace choose <>

Now you may try to drive unlock once more.

In case you have been profitable, then you’re going to get the next message:

Terraform state has been efficiently unlocked!

The state has been unlocked, and Terraform instructions ought to now be capable to
acquire a brand new lock on the distant state.


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments