Problem
When the plan phase of a destroy run completes in Terraform Enterprise, the run fails with the following error message in the plan output:
Failed running command "cd '/terraform' && envdir /env terraform show -json /terraform/terraform.tfplan" (exit 1) Output: Failed to marshal plan to json: error marshaling prior state: unsupported attribute "<some_attribute>"
Prerequisites
- Terraform Enterprise
v202308-1or an earlier version.
Cause
During the plan phase of every run, Terraform Enterprise executes the terraform show command to generate data for services like Sentinel and Cost Estimation.
This error can occur when there is a provider version mismatch between the version recorded in the prior state and the version specified in the current configuration. Changes in the resource schema of a newer provider version can prevent Terraform from correctly marshaling the older state file.
Solutions
To resolve this issue, you must update the state to the newest schema before initiating the destroy run.
Solution 1: Run a refresh-only plan
Start a new refresh-only plan. This action updates the state file with information from the real-world infrastructure, aligning it with the current provider schema without making any changes.
Note: Refresh-only mode is available in Terraform Enterprise v202106-1 or later and requires a workspace using Terraform CLI v0.15.4 or later.
Solution 2: Apply a no-op change
Update the configuration with a no-operation (no-op) change, such as adding a null_resource, and apply the new run successfully. This action forces Terraform to update the state file with the current provider version.
Solution 3: Align provider versions
Update the Terraform configuration to use the same provider version that was used to create the existing state file. This avoids the schema mismatch by ensuring consistency between the configuration and the state.
Outcome
After implementing one of the solutions, the destroy run should complete successfully.