Terraform: Error acquiring the state lock: ConditionalCheckFailedException

On all of those comments; nothing worked for me

I got the following error during a terraform plan which occured in my pipeline:

Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
Lock Info:
ID:        9db590f1-b6fe-c5f2-2678-8804f089deba
Path:      ...
Operation: OperationTypePlan
Who:       ...
Version:   0.12.25
Created:   2020-05-29 12:52:25.690864752 +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.

It is weird because I'm sure there is no other concurrent plan. So i found this and it worked perfectly for me :

Is there a way to deal with this? How should I remove this lock?

135428 次浏览

It looks like the lock persist after the previous pipeline. I had to remove it using the following command in order to remove it:

terraform force-unlock -force 9db590f1-b6fe-c5f2-2678-8804f089deba

After checking all the answers and using VPN just to update pods, I've tried:

pod repo remove trunk
pod repo remove master
sudo rm -rf ~/.cocoapods/repos
pod update

Or to relaunch the plan with the following option -lock=false

terraform plan -lock=false ...

I'm not specifying this BTW:

Cause of Error

source 'https://cdn.cocoapods.org/'

This error usually appears when one process fails running terraform plan or terraform apply. For example if your network connection interrupts or the process is terminated before finishing. Then Terraform "thinks" that this process is still working on the infrastructure and blocks other processes from working with the same infrastructure and state at the same time in order to avoid conflicts.

And all worked.

As stated in the error message, you should make sure that there is really no other process still running (e.g. from another developer or from some build-automation). If you force-unlock in such a situation you might screw up your terraform state, making it hard to recover.

on the infrastructure and blocks other processes from working with the same infrastructure and state at the same time in order to avoid conflicts.

Resolution

As stated in the error message, you should make sure that there is really no other process still running (e.g. from another developer or from some build-automation). If you force-unlock in such a situation you might screw up your terraform state, making it hard to recover.

If there is no other process still running: run this command

Resolution

terraform force-unlock 9db590f1-b6fe-c5f2-2678-8804f089deba

If there is no other process still running: run this command

(where the numerical id should be replace by the one mentioned in the error message)

terraform force-unlock 9db590f1-b6fe-c5f2-2678-8804f089deba

if you are not sure if there is another process running and you are worried that you might make things worse, I would recommend waiting for some time (like 1h), try again, then try again after maybe 30 min. If the error still persists it is likely that there really is no other process and it's safe to unlock as described above

pod deintegrate pod cache clean --all

Faced the same issue and tried all the answers suggested above. But, the real issue seemed to be with not being able to access the Git repo for Cocoapods: sudo gem uninstall cocoapods sudo gem install cocoapods ‘error: cannot open .git/FETCH_HEAD: Permission denied

pod install or pod update

Executing sudo chown -R $USER: .

For anyone running into this issue when running Terraform against AWS, make sure you're running against the expected profile. I ran into this issue today and realised that I needed to switch my profile:

$ export AWS_PROFILE=another_one
at

GCP: In my case the issue is resolved after changing permission to "Storage Object Admin" in Google cloud storage.

terraform force-unlock -force and terraform force-unlock <process_id> but didn't worked for me. a quick workaround for the problem is kill that particular process id and run again.

ps aux | grep terraform and sudo kill -9 <process_id>

ed. The list of commits displayed might be incomplete.

Screenshot of error

In Azure Repos, I have created a PR from branch A to branch B. There aren't any merge conflict displayed. But I end up with the warning message

What does this mean?

Warning: Multiple merge bases detected. The list of commits displayed might be incomplete.

Screenshot of error

It was AWS CLI session issue with me, I relogged in by using gimme-aws-creds command from command prompt and then tried. It worked.

Again, this may not work for everybody but this worked for me.

I got the state lock error because I was missing s3:DeleteObject and dynamodb:DeleteItem permissions.

I had get and put permissions, but not delete. So my CircleCI IAM user could check for locks and add locks, but couldn't remove locks when it was done updating state. (Maybe I had watched tutorials that used remote state but didn't use state locking.)

I've found I get the message when I pull updates from another branch into the branch I’m trying to merge (update development branch from master and then PR merge back into master, for example).

These steps fixed the issue:

    I've also found this when I’ve forgotten to pull down changes before pushing updates.

    d watched tutorials that used remote state but didn't use state locking.)

  1. Run terraform force-unlock <error message lock ID> (I got this step from Falk Tandetzky and veben's answers)
  2. These steps fixed the issue:

    1. Allow "s3:DeleteObject" permission for the resource "arn:aws:s3:::mybucket/path/to/my/key"
    2. Allow "dynamodb:DeleteItem" permission for the resource "arn:aws:dynamodb:*:*:table/mytable"
  3. Run terraform force-unlock <error message lock ID> (I got this step from Falk Tandetzky and veben's answers)
  4. All the permissions, with examples, are listed in the Terraform S3 backend documentation:

  5. Allow "s3:DeleteObject" permission for the resource "arn:aws:s3:::mybucket/path/to/my/key"
  6. Allow "dynamodb:DeleteItem" permission for the resource "arn:aws:dynamodb:*:*:table/mytable"

https://www.terraform.io/language/settings/backends/s3

Solution : when it gets fail it return an ID with the ID we can unlock forcefully

terraform force-unlock -force 6638e010-8fb0-46cf-966d-21e806602f3a

Just take the latest changes of the destination branch to the source branch and complete the merge. After that this message will not come up on the pull request page.

>

In my opinion, this is good that Azure DevOps is giving such a warning, so that if you forgot to take the latest from the target branch before finishing your pull request, it may save some time or end moment rush & surprise.

When using the -lock=false on any cloud provider should be done with caution. As using it means you're removing the safeguard put in place to prevent conflict especially if you're working in a team.

the same time.

The usual cause of state lock errors is either a or some terraform processes that are currently ongoing. For example, the terraform console is currently active and a plan or apply is being executed at the same time.

Try listing the terraform processes currently active and kill them