Remove Provisioned Infra with Terraform Destroy
You can add a Terraform Destroy Workflow step to remove any provisioned infrastructure, just like running the
terraform destroy command. See
destroy from Terraform.
To solve [problem], [general description of How-to solution].
In this topic:
- Before You Begin
- Review: What Gets Destroyed?
- Step 1: Add Terraform Destroy Step
- Step 2: Select Provisioner and Workspace
- Option: Select Delegate
Before You Begin
This topic assumes you have read the following:
- Terraform Provisioning with Harness
- Set Up Your Harness Account for Terraform
- Add Terraform Scripts
- Map Terraform Infrastructure
- Provision using the Terraform Provision Step
- Using the Terraform Apply Command
- Perform a Terraform Dry Run
Review: What Gets Destroyed?
When you use the Terraform Destroy step, you specify the Provisioner and Workspace to use, but Terraform Destroy also needs the Inline Values and Backend Configuration values from the last successful execution of the Terraform Provision or Terraform Apply step.
When the Terraform Provision or Terraform Apply step were executed, Harness saved the Inline Values and Backend Configuration values using a combination of the following:
- Infrastructure Provisioner used.
- Environment used for the Workflow.
- Workspace used (or
defaultif no workspace was specified).
When Terraform Destroy is run, it uses the same combination to identify which Inline Values and Backend Configuration values to use. You simply need to provide the Provisioner and Workspace.
Step 1: Add Terraform Destroy Step
In the Post-deployment Steps of the Workflow, click Add Step, and then select Terraform Destroy.
The Terraform Destroy settings appear.
Step 2: Select Provisioner and Workspace
Select the Terraform Provisioner and Workspace that was used to provision the infrastructure you want to destroy.
Typically, this is the Terraform Provisioner and Workspace used in the Pre-deployment Steps.
Option: Select Delegate
In Delegate Selector, enter the Delegate Selector for the Delegate that you want to execute this step. Typically, this is the same Selector used to select a Delegate in the Terraform Provision step.
Click Submit. The Terraform Destroy step is added to the Workflow.