ljfranklin / terraform-resource

A concourse resource to create infrastructure via Terraform
MIT License
185 stars 85 forks source link

How to destroy the infra created by Terraform #154

Open skdubey opened 3 years ago

skdubey commented 3 years ago

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?

ljfranklin commented 3 years ago

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.

skdubey commented 3 years ago

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".

ljfranklin commented 3 years ago

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

skdubey commented 3 years ago

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