ljfranklin/terraform-resource

How to destroy the infra created by Terraform

skdubey opened this issue · 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?

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.

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

Destroy example:

- put: terraform
resource: terraform-s3-backend
params:
env_name: s3-backend-env
action: destroy
vars:
object_key: ci-pipeline/track1
object_content: "terraform is still neat!"
get_params:
action: destroy

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