Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

terraform state lock の解除方法

More than 1 year has passed since last update.



$ terraform plan

Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
        status code: 400, request id: HUFMTA4D7PN40H4RVR3PBC2FJVVV4KQNSxxxxxxxxxxx
Lock Info:
  ID:        xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
  Path:      tomy-stg-terraform-state/_/tomy-stg/terraform.tfstate
  Operation: OperationTypePlan
  Who:       tomy103@xxx.local
  Version:   0.11.10
  Created:   2018-12-20 23:46:18.414418 +0000 UTC

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.

こうなると何度terraform apply / plan を実行しても上記Errorで実行できません。

他でterraform apply / plan が実行されていないことが分かっていたのでこのロックを手動で解除します。

$ terraform force-unlock xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

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.

これでterraform apply / planが実行できるようになりました。



Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away