terraform-resource icon indicating copy to clipboard operation
terraform-resource copied to clipboard

How to destroy the infra created by Terraform

Open skdubey opened this issue 3 years ago • 4 comments

Hi,

I was able to run terraform-plan and terraform-apply (two separate actions under same Job) to create AWS resources, Which is working fine. However, it raised a question that How can I destroy the resources created by Concourse pipeline either all or a specific resource?

Also, I observed that when Concourse pipeline is created, I have to run terraform-plan and terraform-action manually to run it. Is there way to run all the actions mentioned under same job sequentially?

skdubey avatar May 27 '21 08:05 skdubey

See put.params.action for running terraform destroy: https://github.com/ljfranklin/terraform-resource#put-parameters. This will destroy all resources listed in the statefile, the resource doesn't support destroying a specific resource as that's strongly discouraged by Terraform.

Also, I observed that when Concourse pipeline is created, I have to run terraform-plan and terraform-action manually to run it. Is there way to run all the actions mentioned under same job sequentially?

Does your job have trigger: true on one of the resources, e.g. https://concourse-ci.org/git-trigger-example.html? Not sure I understand the question.

ljfranklin avatar May 27 '21 10:05 ljfranklin

Thanks @ljfranklin again for quick response and help. Regarding destroy, I went through the doc but couldn't understand much. Do we have any sample example for this? Regarding trigger, thanks for pointing, it was set to "false". I will test with "true".

skdubey avatar May 27 '21 15:05 skdubey

Destroy example: https://github.com/ljfranklin/terraform-resource/blob/cadaa3ce340ed59b0fef24e3ff3e495bcd57119f/ci/pipeline.yml#L175-L184

ljfranklin avatar May 28 '21 10:05 ljfranklin

Great, thanks a lot again. It's sufficient for me to start with and explore more.

skdubey avatar May 28 '21 10:05 skdubey