Destroy Workspaces
You can perform specific operations against your workspace configuration. Similarly to provisioning a workspace, you can tear down the infrastructure state from a workspace without deleting the workspace itself. This guide walks you through how to create a Destroy pipeline to run the init
, plan
and destroy
commands with OpenTofu or Terraform.
- Interactive Guide
- Step-by-Step
- YAML
Follow these instructions to provision a workspace within the Harness Visual Editor.
- In the Harness project pane, select Pipelines.
- Click + Create a Pipeline to set up a new pipeline.
- Click Add Stage and select Infrastructure from the Select Stage Type pane.
- Enter a stage name, optional description, and tag, then select Set Up Stage.
- On the Workspace tab, select an existing workspace or click + Create New Workspace to create one.
- Go to the Execution tab. Under Common Operations, select Destroy to configure the workspace destruction process.
- Select Use Strategy to automatically add
init
,plan
, anddestroy
steps, or customize the pipeline by adding steps manually. - Click Save and then Run Pipeline to execute.
The plan-destroy step generates a Terraform plan. This Terraform plan is accessible to all the steps after the IaCM Terraform plan, and can be referenced using the expression <+pipeline.stages.STAGE_ID.spec.execution.steps.STEP_ID.output.outputVariables.parsedPlan>
.
To destroy a workspace via YAML, use the template below. Replace bracketed placeholders as needed.
pipeline:
name: <<PIPELINE NAME>>
identifier: <<PIPELINE IDENTIFIER>>
projectIdentifier: <<PROJECT IDENTIFIER>>
orgIdentifier: <<ORG IDENTIFIER>>
tags: {}
stages:
- stage:
name: Destroy Stage
identifier: destroy_stage
type: IACM
spec:
workspace: <<WORKSPACE ID>>
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
execution:
steps:
- step:
type: IACMTerraformPlugin
name: init
identifier: init
spec:
command: init
timeout: 5m
- step:
type: IACMTerraformPlugin
name: plan
identifier: plandestroy
spec:
command: plan-destroy
description: plan destroy
- step:
type: IACMTerraformPlugin
name: destroy
identifier: destroy
spec:
command: destroy
description: destroy
timeout: 5m
tags: {}
Notice the three steps to execute your init
, plan
and destroy
commands.
After the plan is created, view resources and Terraform outputs on the Resources tab. Check which resources will be added, modified, or removed.