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"
31 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 } 
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:

Portal:

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