# Add cleanup job to remove everything that have been created on your cloud provider by Terraform
The final step is the time to clean up what we built previously.
To remove all things created by Terraform, we will create a destroy
job which calls a terraform destroy (opens new window) command.
Follow those steps to apply all changes described in this step
stack-sample/pipeline/pipeline.yml
groups:
- name: all
jobs:
...
- name: destroy
jobs:
- terraform-destroy
jobs:
...
- name: terraform-destroy
max_in_flight: 1
build_logs_to_retain: 10
plan:
- do:
- get: git_stack
trigger: false
- get: git_config
trigger: false
- *task-merge-stack-and-config
- put: tfstate
params:
action: destroy
terraform_source: merged-stack/
get_params:
action: destroy
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
As you are familiar enough, create a new job that gets our Git, merge parts, get the tfstate file to know the current state of what Terraform has created, then call terraform resource to destroy it.
The only specificity is that we created a dedicated group for this job called destroy
in order to have it into a dedicated section of our pipeline view.
Add and commit those changes in Git:
git add .
git commit -m "Step 9"
git push origin stacks
2
3
Get back to Cycloid's dashboard, and click on the Refresh pipeline
button .
Call this new job and that's it, all cleaned up!
You did it! Well done. Now is the time to review our Advanced Guide.
# Key points to remember
- To remove all things created by Terraform, we create a
destroy
job which calls the terraform destroy (opens new window) command