Thursday, September 21, 2023
HomeSoftware Engineering Error buying the state lock in Terraform

[Solved] Error buying the state lock in Terraform

When you have been handed the Buying state lock error message about ConditionalCheckFailedException: The conditional request then you might have 2 choices for fixing it!

The error appears one thing like this:

Buying state lock. This may occasionally take a number of 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 identical time. Please resolve the problem above and take a look at
│ once more. For many instructions, you'll be able to disable locking with the "-lock=false"
│ flag, however this isn't really helpful.

There are 3 attainable methods to repair this

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

You’ll be able to power unlock the state utilizing the next:

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

Possibility 2: Relaunch the Plan

You’ll be able to run the plan once more with a -lock=false as following:

terraform plan -lock=false ...

Possibility 3: Be sure you use the fitting profile!

Typically the whole lot appears right, however it seems you’re utilizing a unique profile!


Pressure Unlock nonetheless not working?

Typically you will get one other error when attempting to power unlock this:
Didn't unlock state: didn't retrieve lock data: sudden finish of JSON enter

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

View all workspaces obtainable: terraform workspace listing

Swap to a workspace: terraform workspace choose <>

Now you’ll be able to try to power unlock once more.

In case you had been profitable, then you’ll get the next message:

Terraform state has been efficiently unlocked!

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


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments