-->

DEVOPSZONES

  • Recent blogs

    terraform Error: Error acquiring the state lock

     While running "terraform plan" i got the following error:

    Acquiring state lock. This may take a few moments...

    Error: Error acquiring the state lock

    │ 

    │ Error message: state blob is already locked

    │ Lock Info:


    Cause of Error:

    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.

    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.

    Resolution :

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

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

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


    If it still persists , then use "-force"

    terraform force-unlock -force <ID>

    Output:

    Do you really want to force-unlock?

      Terraform will remove the lock on the remote state.

      This will allow local Terraform commands to modify this state, even though it

      may be still be in use. Only 'yes' will be accepted to confirm.


      Enter a value: yes


    Terraform state has been successfully unlocked!


    The state has been unlocked, and Terraform commands should now be able to

    obtain a new lock on the remote state.


    If you are working with terragrunt, try the same command with terragrunt.

    expected output:

    Terraform state has been successfully unlocked!


    The state has been unlocked, and Terraform commands should now be able to

    obtain a new lock on the remote state.


    Or 

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

    terraform plan -lock=false ...
    

    NOTEID you can get it from the error in the previous pipeline.

     Error: Error acquiring the state lock
     
     Error message: ...
     Lock Info:
       ID:        8db590d154328804f089deba

    No comments