There currently isn’t a way to delete all stacks with pulumi stack rm so this is an alternative way to achieve that.

Delete All Stacks in the Current Project

To delete all Pulumi stacks in the current Pulumi project you can run the following command:

1
pulumi stack ls | tail -n +2 | tr -d "*" | awk '{print $1}' | while read -r stack; do pulumi stack rm -y "$stack"; done;

Delete All Stacks Across All Projects

Be careful when doing this.

To delete all Pulumi stacks across all Pulumi projects we need to use pulumi stack ls -a instead of pulumi stack ls. So the full command is:

1
pulumi stack ls -a | tail -n +2 | tr -d "*" | awk '{print $1}' | while read -r stack; do pulumi stack rm -y "$stack"; done;

Command Break Down

List pulumi stacks (use -a option for all stacks across all projects):

1
pulumi stack ls

Start at the second line of the previous output:

1
tail -n +2

Delete all occurrences of *. There is a * character next to the currently selected stack and we need to remove this:

1
tr -d "*"

Print only the first column:

1
awk '{print $1}'

This is a loop in one-liner format. It reads the previous output line by line and assigns each line to an array called stack, then runs the command pulumi stack rm -y on each stack.

1
while read -r stack; do pulumi stack rm -y "$stack"; done;

References