When you have been handed the Buying state lock error message about ConditionalCheckFailedException: The conditional request then you could have 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 Information:
│ 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
│ Information:
│
│ Terraform acquires a state lock to guard the state from being written
│ by a number of customers on the identical time. Please resolve the difficulty above and check out
│ once more. For many instructions, you'll be able to disable locking with the "-lock=false"
│ flag, however this isn't really useful.
There are 3 potential methods to repair this
In brief, you need to delete the lock related. That is achieved by forcing an unlock.
Possibility 1: Power Unlock – Really useful
You’ll be able to drive 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 to use the fitting profile!
Generally the whole lot appears right, but it surely seems you might be utilizing a distinct profile!
AWS_PROFILE=some_other_profile
Power Unlock nonetheless not working?
Generally you may get one other error when making an attempt to drive unlock this:Did not unlock state: didn't retrieve lock data: surprising finish of JSON enter
This often means that you’re within the improper workspace.
View all workspaces accessible: terraform workspace checklist
Change to a workspace: terraform workspace choose <>
Now you’ll be able to attempt to drive unlock once more.
In case you had 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 have the ability to
receive a brand new lock on the distant state.