[Azure] 執行 terraform apply 時,出現 state blob is already locked 錯誤?
今天在執行 terraform apply
時,突然出現 Error acquiring the state lock 的訊息,
細項是說 state blob is already locked…
想想可能是因為 terraform 在上次執行過程中,我按了兩次 Ctrl-C 強制中斷的關係…
$ terraform apply -auto-approve Acquiring state lock. This may take a few moments... ╷ │ Error: Error acquiring the state lock │ │ Error message: state blob is already locked │ Lock Info: │ ID: 013c8f85-f608-9c43-3301-d5cb4b3c386c │ Path: state-container/infra/k8s-resource/az-poc-eu2/state.tf │ Operation: OperationTypeApply │ Version: 1.1.7 │ Created: 2022-03-14 08:10:53.295589 +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 怎樣都不會執行成功…
要怎麼解決呢?
查了一下,原來只要把這個鎖打開就好了 (好像廢話)…
到 Azure > Storage Account 裡,把出問題的 container 裡的檔案找出來,
點下右邊的 … 鈕,再選 Break lease:
這時鎖的狀態就變成 Broken:
此時就可以再次執行 terraform apply
囉~
參考資料:terraform – Error locking state: Error acquiring the state lock: state blob is already locked
(本頁面已被瀏覽過 250 次)