Terraform plan getting Error: Failed to decode resource from state

Terraform initialize is working fine but when I do terraform plan getting below error.

Error: Failed to decode resource from state │ │ Error decoding "azurerm_mssql_database.db" from previous state: unsupported attribute "extended_auditing_policy"

If I comment this particular resource then we start getting error for other resource.

Can some one please help me ?

Error: Failed to decode resource from state │ │ Error decoding "azurerm_mssql_database.db" from previous state: unsupported attribute "extended_auditing_policy"

3

1 Answer

I tried in my environment and got below results:

Initially I tried with extended audit policy with new terraform provider version and got the same error:

extended_auditing_policy { storage_endpoint = module.storageaccount.storage_account.self.primary_blob_endpoint storage_account_access_key = module.storageaccount.storage_account.self.primary_access_key storage_account_access_key_is_secondary = false retention_in_days = 30 } 

enter image description here

This problem occurs when attempting to import data using a provider version that is older than the one that was used to create the current state. The earlier provider version won't be able to decode an unknown attribute while loading the state file during the import if the attribute was added in the newer version of the provider.

I tried with new azurerm_mssql_server_extended_auditing_policy resource to solve this problem.

Terraform.tf

provider "azurerm" { features {} } resource "azurerm_resource_group" "vs" { name = "<rg name>" location = "West Europe" } resource "azurerm_mssql_server" "ex" { name = "demosqlserver3261" resource_group_name = azurerm_resource_group.vs.name location = azurerm_resource_group.vs.location version = "12.0" administrator_login = "missadministrator" administrator_login_password = "AdminPassword123!" } resource "azurerm_mssql_database" "ext" { name = "demodb3261" server_id = azurerm_mssql_server.ex.id } resource "azurerm_storage_account" "vst" { name = "venkat678" resource_group_name = azurerm_resource_group.vs.name location = azurerm_resource_group.vs.location account_tier = "Standard" account_replication_type = "GRS" } resource "azurerm_mssql_database_extended_auditing_policy" "example" { database_id = azurerm_mssql_database.ext.id storage_endpoint = azurerm_storage_account.vst.primary_blob_endpoint storage_account_access_key = azurerm_storage_account.vst.primary_access_key storage_account_access_key_is_secondary = false retention_in_days = 6 } 

Console:

enter image description here

Portal:

enter image description here

Reference: Import fails with "Error: Invalid resource instance data in state" – HashiCorp Help Center

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like