Terraform rollback to some input state

Viewed 2570

I have a terraform state file with me. Can I use that to provision the infra instead of providing terraform config files(.tf)?

I basically need the functionality to support rollbacks. So, in case some failure happens while running some terraform command, I want to rollback to the previous state.

2 Answers

Rollbacks are not well-supported. You can do this in Terraform Enterprise or Terraform Cloud, but it is not trivial. Here is a link to the HashiCorp Support article that explains the process.

Basically, you will find the last known good state file, download it to your local system, change the backend, then move the state file. If you're really lucky, you can pull the state and then push the desired state. Be careful around the version of the CLI terraform and the version in Enterprise or Cloud.

Related