如何解决升级Terraform提供程序会导致“状态中的资源实例数据无效”错误
我将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"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。