Problem
When running local state commands such as terraform state rm or terraform import against a state file managed in HCP Terraform, you may encounter the following error:
$ terraform state rm databricks_library.dotenv Removed databricks_library.dotenv Error saving the state: unsupported attribute "application_id" The state was not saved. No items were removed from the persisted state. No backup was created since no modification occurred. Please resolve the issue above and try again.
Cause
This error occurs when the version of a provider in your local Terraform configuration does not match the provider version that was used to write the latest state file in HCP Terraform.
When Terraform attempts to save the modified state, it validates the entire state file against the local provider schemas. If a resource attribute, such as application_id in this example, was added, removed, or changed in a different provider version, Terraform reports an error because the local provider does not recognize the attribute stored in the state.
Note that the error may originate from a resource managed by a different provider than the one you are directly interacting with. For example, you might attempt to remove a resource managed by the databricks provider, but the error is caused by a provider version mismatch for a resource managed by the azurerm provider within the same state file.
Solution
To resolve this issue, you must align your local provider versions with those recorded in the state file.
-
Initialize the configuration: Run
terraform initin your local configuration directory. This command reads your configuration's provider requirements and downloads the correct versions, ensuring they match what is expected by the state file. -
Verify provider versions: After initialization, you can inspect the
.terraform.lock.hclfile to confirm that the provider versions match those used in the HCP Terraform workspace's latest state version. -
Enable trace logging for detailed analysis (Optional): If the issue persists, you can enable trace logging to get more detailed information about the provider versions being used during the operation.
$ export TF_LOG=TRACE
The trace output will show the exact provider versions being loaded and used.
-
Consult the Terraform Registry: You can investigate attribute and argument changes between provider versions by consulting the official Terraform Registry. While the error message may not specify the resource, you can search for the problematic attribute (
application_id) within your state file to identify the resource and its provider, then check that provider's documentation for version changes.
After ensuring the local provider versions match the state file, the unsupported attribute error will be resolved, and state commands will execute successfully.