LoginSignup
22
7

More than 5 years have passed since last update.

terraform state lock の解除方法

Last updated at Posted at 2018-12-21

はじめに

terraformのstatelockにDynamoDBを使っていて、何かの拍子に意図せずロックされたままの状態になってしまったときのロック解除方法の例を残しておきます。

$ 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
  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.

こうなると何度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が実行できるようになりました。

参考ドキュメント

22
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
7