'How can I destroy my infra when pipeline fails on 'build' stage?

My base .gitlab-ci.yml code is the following

include:
 - template: Terraform/Base.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
stages:
 - init
 - validate
 - build
 - deploy
 - cleanup
init:
 extends: .terraform:fmt
validate:
 extends: .terraform:validate
build:
 extends: .terraform:build
deploy:
 extends: .terraform:deploy
 dependencies:
   - build
 allow_failure: true
cleanup:
 extends: .terraform:destroy
 dependencies:
   - build

The build stage failed but did create some resources in AWS. Then, cleanup successes with the following:

Terraform has been successfully initialized!
No changes. No objects need to be destroyed.
Either you have not created any objects yet or the existing objects were already deleted outside of Terraform.

Please keep it simple, I'm a newborn baby into this



Solution 1:[1]

It would help to know exactly which terraform commands your pipeline jobs are running.

Generally though, you should be able to comment out the TF code for your resource(s) and run the pipeline again to delete them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A. Kendall