Rollback Provisioned Infra with the Terraform Rollback Step
Harness includes a Terraform Rollback step that you can use to roll back your provisioned infrastructure and resources and return your environment to its pre-deployment state.
In this topic:
- Before You Begin
- Review: Terraform Rollback
- Step 1: Add the Terraform Rollback Step
- Step 2: Reference the Provisioner Identifier
- See Also
Before You Begin
- Terraform Provisioning with Harness
- Provision Target Deployment Infra Dynamically with Terraform
- Provision with the Terraform Apply Step
Review: Terraform Rollback
When rollback happens, Harness rolls back the provisioned infrastructure to the previous successful version of the Terraform state.
Harness won't increment the serial in the state, but perform a hard rollback to the exact version of the state provided.
Harness determines what to rollback using the Provisioner Identifier.
If you've made these settings expressions, Harness uses the values it obtains at runtime when it evaluates the expression.
Let's say you deployed two modules successfully already: module1 and module2. Next, you try to deploy module3, but deployment failed. Harness will roll back to the successful state of module1 and module2.
However, let's look at the situation where module3 succeeds and now you have module1, module2, and module3 deployed. If the next deployment fails, the rollback will only roll back to the Terraform state with module3 deployed. Module1 and module2 weren't in the previous Terraform state, so the rollback excludes them.
Step 1: Add the Terraform Rollback Step
You can add the Terraform Rollback step in two places:
- The Rollback steps of a stage's Infrastructure, in Dynamic Provisioning:
- The Rollback steps of a stage's Execution:
Add the Terraform Rollback step.
In Name, enter a name for the step. You can use the name to reference the Terraform Rollback settings.
Step 2: Reference the Provisioner Identifier
In Provisioner Identifier, enter the same Provisioner Identifier you used in the Terraform Plan and Apply steps.
Click Apply Changes.
The Terraform Rollback step is added to the Rollback steps.