Help us understand the problem. What is going on with this article?

terraform state lock の解除方法

はじめに

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

参考ドキュメント

https://www.terraform.io/docs/commands/force-unlock.html

Why do not you register as a user and use Qiita more conveniently?
  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
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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