hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
439 stars 232 forks source link

Removing an Attribute Can Cause "Invalid resource instance data in state" Errors on Import #918

Closed bflad closed 2 years ago

bflad commented 2 years ago

SDK version

v2.10.1

Relevant provider source code

https://github.com/hashicorp/terraform-provider-azurerm/blob/3e162d1aaec9ccf9b9174bd216d0ae6ba989323a/internal/services/mssql/mssql_database_resource.go#L38-L41

https://github.com/hashicorp/terraform-provider-azurerm/blob/3e162d1aaec9ccf9b9174bd216d0ae6ba989323a/internal/services/mssql/mssql_database_resource.go#L760

Likely related:

https://github.com/hashicorp/terraform-provider-azurerm/blob/3e162d1aaec9ccf9b9174bd216d0ae6ba989323a/internal/services/mssql/migration/database_v0_to_v1.go#L57

Terraform Configuration Files

Seems irrelevant as it may only pertain to import, but here's an example:

resource "azurerm_mssql_database" "mssql_database" {
  name = "tentaclearmy-mssql-database-${lower(var.environment)}"
  server_id = azurerm_mssql_server.mssql_server.id
  max_size_gb = 2
  sku_name = "Basic"
}

Debug Output

To be gathered.

Expected Behavior

Terraform imports resource successfully.

Actual Behavior

Error on import:

$ terraform import azurerm_mssql_database.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/databases/example1
...
Error: Invalid resource instance data in state
│
│   on /Users/.../Octopus/TentacleArmy/terraform/main.tf line 71:
│   71: resource "azurerm_mssql_server" "mssql_server" {
│
│ Instance azurerm_mssql_server.mssql_server data could not be decoded from the state: unsupported attribute "extended_auditing_policy".

Steps to Reproduce

  1. terraform import on a resource with a recently removed attribute

References

bflad commented 2 years ago

Being tracked as a core issue over here: https://github.com/hashicorp/terraform/issues/30746

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.