terraform 状态文件已锁定,如何解锁

Ami*_*rma 43 terraform terraform-state

我正在尝试使用基本的 terraform 命令,例如plan,但不能,因为 terraform 状态已锁定(见下文。)

\n

我知道我是唯一与此 terraform 实例交互的人或进程,并在Who下面的锁行中看到我的名字。我想这可能是当我按下时发生的Ctrl-C地形提示时发生的。

\n

我该如何解锁?

\n
$ terraform plan\n\xe2\x95\xb7   \n\xe2\x94\x82 Error: Error acquiring the state lock\n\xe2\x94\x82   \n\xe2\x94\x82 Error message: ConditionalCheckFailedException: The conditional request failed\n\xe2\x94\x82 Lock Info:\n\xe2\x94\x82   ID:        xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n\xe2\x94\x82   Path:      xxx \n\xe2\x94\x82   Operation: OperationTypePlan\n\xe2\x94\x82   Who:       xxx \n\xe2\x94\x82   Version:   1.3.4\n\xe2\x94\x82   Created:   2022-11-15 19:51:21.368168706 +0000 UTC \n\xe2\x94\x82   Info:           \n\xe2\x94\x82   \n\xe2\x94\x82   \n\xe2\x94\x82 Terraform acquires a state lock to protect the state from being written\n\xe2\x94\x82 by multiple users at the same time. Please resolve the issue above and try \n\xe2\x94\x82 again. For most commands, you can disable locking with the "-lock=false"\n\xe2\x94\x82 flag, but this is not recommended.\n\xe2\x95\xb5   \n
Run Code Online (Sandbox Code Playgroud)\n

Jea*_*ond 75

您可以使用force-unlock命令手动解锁状态:

terraform force-unlock LOCK_ID
Run Code Online (Sandbox Code Playgroud)

锁 ID 通常会显示在错误消息中。

如果您的状态是本地状态并且被本地进程锁定,则它可能不起作用。如果是这种情况,请尝试终止该进程并重试。


小智 7

要解锁状态而无需键入确认:

terraform force-unlock -force LOCK_ID
Run Code Online (Sandbox Code Playgroud)