gpt4 book ai didi

terraform - 升级 terraform provider 导致 "invalid resource instance data in state"错误

转载 作者:行者123 更新时间:2023-12-04 09:07:54 24 4
gpt4 key购买 nike

我将 Terraform AzureRM 提供程序从 1.44 升级到 2.23。 Terraform 版本是 0.13.0。有趣的是,现在我尝试运行 terraform plan我收到多个“状态无效的资源实例数据”错误。
它们看起来像这样:

Error: Invalid resource instance data in state

on .terraform\modules\redacted\terraform\modules\keyvault\main.tf line 1:
1: resource "azurerm_key_vault" "keyvault" {

Instance module.redacted.module.keyvault.azurerm_key_vault.keyvault data could
not be decoded from the state: unsupported attribute "sku".
我的状态文件在 Azure 存储中。在查看状态文件时,我们看到了问题:
    {
"module": "module.redacted.module.keyvault",
"mode": "managed",
"type": "azurerm_key_vault",
"name": "keyvault",
"provider": "module.redacted.provider.azurerm",
"instances": [
{
...
"sku": [
{
"name": "standard"
}
],
"sku_name": "standard",
....
为 keyvault 定义 sku 的最新方法是使用“sku_name”属性。但是旧的方式已经卡在状态文件中,现在正在引起问题。
升级提供程序以便清除状态文件的首选方法是什么?或者这是必须手动完成的事情?

最佳答案

注意:我无法重现该问题。我从 1.44.0 到 2.23.0。我看到 sku[{}] 状态信息在状态文件中。当我使用 2.23.0 运行应用程序时,它被删除了。
最安全的做法是进行备份,删除状态并导入它。
删除状态并导入它(升级前检查状态会产生错误)

▶ terraform state show azurerm_key_vault.example 
unsupported attribute "sku"
# azurerm_key_vault.example:
resource "azurerm_key_vault" "example" {

▶ terraform state rm azurerm_key_vault.example
Removed azurerm_key_vault.example
Successfully removed 1 resource instance(s).
▶ terraform import azurerm_key_vault.example /subscriptions/redacted/resourceGroups/example-resources/providers/Microsoft.KeyVault/vaults/pearcec
azurerm_key_vault.example: Importing from ID "/subscriptions/redacted/resourceGroups/example-resources/providers/Microsoft.KeyVault/vaults/pearcec"...
azurerm_key_vault.example: Import prepared!
Prepared azurerm_key_vault for import
azurerm_key_vault.example: Refreshing state... [id=/subscriptions/redacted/resourceGroups/example-resources/providers/Microsoft.KeyVault/vaults/pearcec]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.


▶ terraform state show azurerm_key_vault.example | Select-String "sku"
InputStream:12: sku_name = "standard"

关于terraform - 升级 terraform provider 导致 "invalid resource instance data in state"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63411522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com