0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Terraform/CDKTF: Local state cannot be unlocked by another process

Posted at

はじめに

CDKTFでAzure バックエンドのとき,cdktfコマンドをCtrl+Cで止めるとロックのエラーが出ます(私はopentofuを使っています)。

                      │ Error: Error acquiring the state lock
                      │ 
                      │ Error message: state blob is already locked
                      │ Lock Info:
                      │   ID:        24873109-6cd4-7418-c0df-e8e721ba84f1
                      │   Path:      tfstate/prod.terraform.tfstate
                      │   Operation: OperationTypeApply
                      │   Who:       node@01486bec915d
                      │   Version:   1.6.0
                      │   Created:   2025-03-25 19:21:21.966895867 +0000 UTC
                      │   Info:
                      │ 
                      │ 
                      │ OpenTofu 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

ロックを外そうとすると以下のエラーになることがあります

 $ tofu force-unlock 24873109-6cd4-7418-c0df-e8e721ba84f1
Local state cannot be unlocked by another process

別プロセスのterraformを殺すと良いよ,というページがいくつか見つかるのですが,そのようなプロセスは存在しません。
困った...

解決方法

image.png
Azure Portalでストレージアカウントを開くと,Pathで指定されているオブジェクトがあります。
そのオブジェクトが「リース中」になっているはずなので,三点ダッシュから「リースの解放」を行うと,「Local state」のアンロックになります。

このページの解説を見ると,terraform step には Phase1とPhase2があり,Phase1をLocal stateと表現しているようです。
言いたいことはわかるんですが,紛らわしいです。
ローカルファイルを探して時間をロスしてしまいました...

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?