Terraform 状态用错误数据替换提供者更新状态

问题描述

我们升级terraform 版本,我们遇到了 terraform 远程状态的问题。 Basiacaly 我运行此命令来更新 azurerm 提供程序:

terraform state replace-provider 'registry.terraform.io/-/azurerm' 'registry.terraform.io/hashicorp/azurerm'

现在,当我运行 plan 命令时,它显示了一些错误。所有都是相同的,但如果不同则是资源。例如:

To work with module.name.module.lb_name.azurerm_lb_probe.instance
its original provider configuration at
provider["registry.terraform.io/-/azurerm"] is required,but it has been
removed. This occurs when a provider configuration is removed while objects
created by that provider still exist in the state. Re-add the provider
configuration to destroy
module.name.module.lb_name.azurerm_lb_probe.instance,after which
you can remove the provider configuration again.

基本上状态已更新,提供程序如下所示:

"provider": "provider.azurerm"

但它应该是这样的:

"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]"

有没有办法通过 terraform 命令更新它,或者修复它的唯一方法是手动编辑状态文件

解决方法

当您使用以下命令替换 Terraform 升级的提供程序时:

terraform state replace-provider 'registry.terraform.io/-/azurerm' 'registry.terraform.io/hashicorp/azurerm'

好的,没问题。然后你可以使用下面的命令来检查当前的提供者:

terraform providers

屏幕截图显示如下:

enter image description here

此时提供者与要求相同。然后您需要再次初始化以使用以下命令拉取当前提供者以替换现有提供者:

terraform init

enter image description here

这是您错过的步骤。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...