How to delete multiple stacks with dependencies

Last updated: September 15, 2025

Currently, there is no bulk-delete feature for stacks in Spacelift. When deleting multiple stacks that have dependencies, you must delete them one at a time in reverse dependency order to ensure resources, state, and VCS links are cleaned up correctly.

Safe deletion process

Always delete stacks in reverse dependency order - this means deleting dependent stacks first, then their dependencies. This approach ensures proper cleanup of resources and maintains data integrity.

Methods for deleting multiple stacks

You can choose from the following approaches:

API approach

Use the Spacelift API to:

  1. Create a dependency-ordered list of your stacks

  2. Iterate over this list in reverse order

  3. Call the stack-delete GraphQL mutation for each stack

Terraform approach

Use the Terraform method with the following steps:

  1. Use the spacelift_stack_destructor resource for resource teardown

  2. Chain destructors with depends_on to enforce proper deletion order

  3. Remove the stacks after resources are torn down

Future improvements

Spacelift is tracking a feature request to manage multiple stacks as a collection, which would include group lifecycle operations (creation, update, and deletion) with automatic dependency awareness. You can upvote this feature request here.

For more information about stack dependencies and deletion, see the stack dependencies documentation.