在初始化期间,Terraform无法找到azurerm后端存储



我已经创建了一个Azure存储帐户,用作Terraform的后端状态存储,并且我能够从运行Terraform命令的Azure DevOps管道中写入该帐户。我可以在Storage Account中看到容器,并确认它具有来自管道执行的具有相同键的状态内容。但是,当我尝试手动运行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.

我的主。Tf文件有:

terraform {
backend "azurerm" {}
}

如前所述,这个相同的terraform init命令在ADO管道中的Bash脚本中调用时可以工作,因此不确定可能是什么问题。如有任何调试建议,请参考。

发现问题….terraform文件夹中的状态信息与新后端冲突。一旦我清除了它,地形初始化命令运行正常

最新更新