【问题标题】:Terraform unable to find azurerm backend storage during initTerraform 在初始化期间无法找到 azurerm 后端存储
【发布时间】:2021-11-26 17:20:35
【问题描述】:

我创建了一个 Azure 存储帐户,用作 Terraform 的后端状态存储,并且我能够从运行 Terraform 命令的 Azure DevOps 管道写入该帐户。我可以在存储帐户中看到容器,并确认它具有来自管道执行的状态内容,具有相同的密钥。但是,当我尝试使用相同的后端存储“手动”运行 Terraform 时,我收到一个错误,它无法找到该容器:

$ terraform init -backend-config="storage_account_name=<redacted>" -backend-config="container_name=auto-api-tfstate" -backend-config="access_key=<redacted>" -backend-config="key=dev-internal2/dev-internal2.tfstate:us"
Initializing modules...

Initializing the backend...
Backend configuration changed!

Terraform has detected that the configuration specified for the backend
has changed. Terraform will now check for existing state in the backends.



Error: Error inspecting states in the "azurerm" backend:
    storage: service returned error: StatusCode=404, ErrorCode=ContainerNotFound, ErrorMessage=The specified container does not exist.
RequestId:89a9b361-a01e-00b1-0fb4-ba5d51000000
Time:2021-10-06T13:18:41.2460433Z, RequestInitiated=Wed, 06 Oct 2021 13:18:40 GMT, RequestId=89a9b361-a01e-00b1-0fb4-ba5d51000000, API Version=2016-05-31, QueryParameterName=, QueryParameterValue=

Prior to changing backends, Terraform inspects the source and destination
states to determine what kind of migration steps need to be taken, if any.
Terraform failed to load the states. The data in both the source and the
destination remain unmodified. Please resolve the above error and try again.

我的 main.tf 文件只有:

terraform {
    backend "azurerm" {}
}

如前所述,当在 ADO 管道的 Bash 脚本中调用时,同样的 terraform init 命令有效,因此不确定可能是什么问题。任何有关调试的建议表示赞赏。

【问题讨论】:

  • 您用于从管道验证到 azure 的身份与手动身份如何?该身份是否具有存储 Blob 数据读取器等正确权限?您是手动创建存储帐户和容器还是由管道处理?您使用的是哪个版本的 terraform?
  • @KedMardemootoo:-我手动创建了 Azure 存储帐户和容器,所以这不是时间问题(特别是考虑到在管道中使用 Terraform 能够将其状态写入容器)。 - 标识是存储帐户的 Azure 门户刀片中的访问密钥。我手动使用的“terraform init”语法与管道运行相同。
  • @KedMardemootoo,Terraform 的版本也是 v0.12.6(固然旧,但它与我们正在使用的开源提供商兼容)。

标签: terraform azure-rm


【解决方案1】:

发现问题... .terraform 文件夹中存在与新后端冲突的状态信息。一旦我清除了它,“terraform init”命令就会按预期工作。

【讨论】:

    猜你喜欢
    • 2021-07-22
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2018-06-03
    • 1970-01-01
    相关资源
    最近更新 更多