错误锁定状态:获取状态锁定时出错:状态 blob 已被锁定

All*_* Xu 3 terraform terraform-provider-azure

当我尝试执行任何操作时出现此错误:

Error locking state: Error acquiring the state lock: state blob is already locked

如何列出当前拥有锁的人以及获得锁的时间?

XIA*_* LI 56

解决此问题最简单的方法是:

\n

(1) 导航到存储帐户,

\n

(2) 然后到 Azure 门户中保存状态文件的容器。

\n

(3) blob 将显示为 \xe2\x80\x98 Leased(3) 该 blob 将在租用状态列下

\n

(4)选择状态文件,打\xe2\x80\x98断租约\xe2\x80\x99 按钮。

\n

*仅供参考:您需要 PIM(特权身份管理 (PIM))来执行此操作。

\n

引用修复 Azure 中的 Terraform \xe2\x80\x98Error getting state lock\xe2\x80\x99

\n

在此输入图像描述

\n


opH*_*AME 5

取决于用于状态锁定的机制。

您可以在配置中看到这一点(例如在 terraform.tf 中,当用作文件名时..)

terraform {
  required_version = "0.13.4"
  backend "s3" {
    bucket         = "my.state.bucket.for.terraform"
    key            = "infra/my.tfstate"
    region         = "eu-central-1"
    encrypt        = true
    dynamodb_table = "my.locking.table.in.dynamo"
  }
}
Run Code Online (Sandbox Code Playgroud)

如果使用 dynamobdb(在 aws 上),只需检查表。对于 PostgreSQL 或其他任何内容也是如此。

要修复它,您可以从客户端释放状态:

terraform force-unlock <ID_OF_LOCK_SHOWN_IN_ERROR>
Run Code Online (Sandbox Code Playgroud)