Skip to main content

Add better support for Terraform/Tofu destroy

We are having issues with the way Terraform/Tofu destroy lifecycle is handled.

Currently there are two ways to run a destroy for one of these stacks:

  1. Run a task where you manually type in “terraform destroy -auto-approve”

  2. Delete the stack and select the option to destroy resources managed by the stack

Both of these methods have some obvious downsides:

Tasks are not intuitive for operational users of Spacelift that don’t commonly destroy stacks. Destroy lifecycle hooks are not executed as part of tasks so the destroy process may fail or be incomplete when run with a task.

Deleting the stack doesn’t support all use cases. In some cases we want to destroy the resources managed by a stack but not the stack itself. We use the stack to create resources again using the same configuration later.

Most importantly:

both methods to not provide a way for us to review the destroy plan and choose to confirm or reject the destroy. There are many reasons a destroy plan may not be acceptable and the underlying project may need unexpected changes before proceeding.

Spacelift already has a nice UX for other parts of the TF lifecycle. We would like to option to trigger a destroy, where the destroy lifecycle is executed with hooks and all, and where we get the opportunity to review the destroy plan and confirm or reject it.

Workaround
No
Problem
Status: ⚙️ In Progress11 comments

Log in to comment and vote

Comments11

  • Azure Chipmunk

    •

    Sep 25, 2024

    I’ll agree with this. There’s a “workaround” in the sense that the stack still exists (and URLs pointing to it still resolve), so you can just hit the “back” button in the browser and go look at the stack’s runs to see the destroy run.

    However, it disappears from the stack list opaquely. The resolution to this is to not silently hide the stack while it’s destroying, but keep it in the list with the “destroying” status until it’s actually deleted.

  • Natalia Gazda

    Team•

    Feb 26, 2025

    @Nick Strause thanks for submitting that! We have some work planned around redesigning deletion of resources and stacks for next quarter. I can’t promise that we will do exactly what you’re asking for since we haven’t started yet and defined the scope, but we will look into it. I might reach out again, once we start the discovery :)

  • Yellow Mirror

    •

    Oct 14, 2024

    Strongly agree. Both stacks and modules (tests) need more visible destroy workflows. It’s especially bad when a destroy action fails, and the Spacelift-managed state is “gone”, leaving a lot of manual cleanup. Really, the destroy action needs to be a first-class citizen in the “regular” Spacelift run workflow, not some separate thing handled by the destructor resource without a visible run and logs.

    I think I figured out how to “make it so”, by injecting a couple environment variables, TF_CLI_ARGS_plan=-destroy and TF_CLI_ARGS_apply=-destroy. Still testing, but expecting to be able to trigger a proposed/tracked run and have the destroy action execute. Feels like a bit of a hack, but if it works I’ll incorporate it into my workflow for stacks. Still need a better solution for module tests.

    • Yellow Mirror

      •

      Oct 22, 2024

      Finished testing and sure enough, works great to add the environment variables, TF_CLI_ARGS_plan=-destroy and TF_CLI_ARGS_apply=-destroy. Then we trigger a run and the resources get cleaned up nicely, and any errors are fully recoverable since the stack and its state still exist.

  • Orange Pond

    •

    Jan 14, 2025

    Totally agree. Have been looking for the functionality described here and kept thinking that I just wasn’t looking in the right place. It’s nice to hear that others are seeking the same set of capabilities.

  • Gold Pear

    •

    Sep 22

    This would be really useful to not have to when we simply want to destroy the resources but not the stack. Please make this doable from both spacectl and the UI .

  • Yellow Mirror

    •

    Feb 11, 2025

    Definitely looking for this feature. You can fake it a little, by adding envs to the stack: `TF_CLI_ARGS_plan=-destroy` and `TF_CLI_ARGS_apply=-destroy`. I mentioned that over on another request also:

    https://feedback.spacelift.io/p/deleting-of-stack-resources-should-be-more-visible/comment/671819387cf2ebb27de6417d

  • Orange Pond

    •

    Feb 19, 2025

    Strongly agree. Support for stack destruction is inadequate. It’s both confusing (invisible) and problematic (can be hard to recover from when something goes wrong).

  • Yellow Mirror

    •

    Jun 3, 2025

    Adding another workaround, by adding envs to the stack: TF_CLI_ARGS_plan=-destroy and TF_CLI_ARGS_apply=-destroy

  • Gray Bear

    •

    Jun 11

    +1 from me for having this. I get not everything can be GUI and yea as a TF user I should be shell friendly but sometimes its nice to just click a button vs having context switch into whats the path for the tfvars file for this env?

    Spacelift has all the pieces so putting a little destroy button should be easy and if I screw up and delete it thats on me!

  • Black Pumpkin

    •

    Sep 28

    Any update on this?? :’)