The current version of Terraform Enterprise (TFE) and Terraform Cloud (TFC) do not provide a feature to revert state within the application. You can, however, use Terraform on the command line to push a state file into a workspace to become the current state.
- To obtain the desired state, navigate to the workspace’s States list, select the desired state, and click "Download" or “Download raw” to download the raw state file to your local machine.
- Configure Terraform locally with a TFE backend and run
terraform initas described in that article.
- With the
remotebackend configured and Terraform initialized, the
state rmcommands are supported. These commands enable direct modification of the state within the Terraform Enterprise or Terraform Cloud workspace.
- In some scenarios, such as if the state in Terraform Enterprise or Terraform Cloud was updated incorrectly or corrupted, direct state manipulation may be required. In these cases, you may pull the state file to the local directory using for editing using the following command.
$ terraform state pull
The state may then be manipulated and subsequently uploaded using the following command, where
/path/to/statefile.json is the updated state file.
$ terraform state push /path/to/statefile.json
- Terraform’s state (mv|rm|push) and also Terraform’s import commands will modify the version of Terraform CLI in the state file to the version from which you are running the CLI command. Please make sure that you are using the same version of Terraform CLI as configured in the target workspace to avoid a conflict of the CLI version.
- This is
terraform state pushand not
terraform pushis deprecated and does not operate in the current version of TFE.
- Please visit Import Terraform configuration tutorial on learn.hashicorp.com for more sample of importing resources into Terraform state.
- Please visit Manage Resources in Terraform State tutorial on learn.hashicorp.com for more sample of managing resources in Terraform state.