terraformgitlab-ci

Terraform: Error acquiring the state lock: ConditionalCheckFailedException


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. Is there a way to deal with this? How should I remove this lock?


Solution

  • 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 <ID>
    

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

    terraform plan -lock=false ...
    

    NOTE: ID you can get it from the error in the previous pipeline.

    │ Error: Error acquiring the state lock
    │ 
    │ Error message: ...
    │ Lock Info:
    │   ID:        9db590f1-b6fe-c5f2-2678-8804f089deba
    │ ...