terraform-github-actions icon indicating copy to clipboard operation
terraform-github-actions copied to clipboard

Check if workspace exists before terraform destroy in destroy-workspace

Open DCamma opened this issue 8 months ago • 1 comments

Suggestion

Use-case

My use case is the following:

  • our feature branches are deployed whenever we open a PR and use the dflook tf-apply action selecting a workspace to differentiate from the main environment, deploying the testing infrastructure.
  • feature branch PRs can remain open for a while but infrastructure might be destroyed by auto-cleanup jobs to reduce costs and are re-created when a new commit is pushed.
  • On PR close we use the dflook destroy-workspace action, but the infra (and the workspace) might already be gone. Hence the dflook action fails not finding the workspace when attempting the destroy.

Proposal:

I would be interested in understanding if it is within the project scope to check if a workspace exists before running the terraform destroy and if the workspace doesn't exist simply terminate successfully the destroy-workspace job.

We implemented the check on our side, but I thought of proposing to handle this use case if others need it as well. Additionally there could be a flag: check-if-workspace-exists or fail-if-workspace-doesn't-exist with defaults that retain the current functionalities.

I would be happy to open a PR exploring this concept.

DCamma avatar Feb 13 '25 14:02 DCamma