Introduction
There are some scenarios where you may need to downgrade the version of the Terraform command-line tool used by HCP Terraform or Terraform Enterprise.
In workspaces that have already applied changes with a higher version of Terraform, the state file will not allow you to use a lower version. You must perform manual steps to use a lower version of Terraform.
Expected Outcome
A remote state file compatible with the desired older Terraform version.
Prerequisites
This guide applies to Terraform versions between 0.14.x and 1.0.x only.
Use Case
Reasons for downgrading the Terraform version include:
- Provider version incompatibility with the current Terraform version.
- An inadvertent upgrade of the Terraform version in your workspace.
Procedure
- Follow the steps in the guide for Using the remote backend and Terraform CLI to run plan and state operations locally. For step 7 in that guide, modify the Terraform Version setting to match the version you are downgrading to. Ensure your local Terraform CLI version matches this desired version. You can find all Terraform CLI releases on the releases page.
- In the target workspace in HCP Terraform or Terraform Enterprise, navigate to the States tab. Select the latest state record and download the state file to the local directory that contains your Terraform configuration.
-
Open the downloaded state file in a text editor and increment the
serialvalue by 1. Adiffof the change may look like this.{ "version": 4, "terraform_version": "1.0.2", - "serial": 3, + "serial": 4, ... } -
Push the modified state file back to the workspace using the
terraform state pushcommand with the-ignore_remote_versionoption. This option is necessary to bypass the version check. For example, if your state file is namedsv-zzz.tfstate, run the following command.$ terraform state push \ -ignore_remote_version \ ./sv-zzz.tfstate
Additional Information
This guide only covers Terraform versions up to 1.0.x. The HCP Terraform cloud integration, introduced in Terraform 1.1.0, supersedes the behavior of the remote backend referenced in this guide. Additionally, the Terraform v1.x Compatibility Promise should allow downgrading from a later v1.x release to an earlier v1.x release, provided you are not using language features from the later release.