Introduction
This article describes how to troubleshoot an Error: Invalid resource instance data in state error that can occur during a terraform import operation.
Problem
When you import a resource into Terraform state, the operation fails with an error message similar to the following output:
Error: Invalid resource instance data in state
on /path/to/configuration/file.tf line 1:
16: resource "resource_type" "resource_name" {
Instance resource_type.resource_name data could not be decoded from the
state: unsupported attribute "unknown_attribute_name".Cause
This error occurs when you attempt a terraform import using a provider version that is older than the version used to write the current state file. If a resource attribute was added in a newer version of the provider, the older provider version cannot decode this unknown attribute when it reads the state file during the import process.
Solution
To resolve this issue, ensure that your local provider versions match the versions used to manage the existing state.
-
Check Provider Versions: Verify that the provider versions used by the configuration are consistent across all environments where you run Terraform commands. You can check the currently installed provider versions by running the
terraform versioncommand. -
Use the Dependency Lock File: If you are using Terraform v0.14 or newer, commit the
.terraform.lock.hclfile to your version control system. This file ensures thatterraform initinstalls the same provider versions in any environment, which prevents version mismatch issues.
Additional Information
For more details on managing provider versions, refer to the official Terraform documentation: