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:

Shell
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

Warning
It should go without saying but, 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:

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

Command Breakdown

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

Shell
pulumi stack ls

Start at the second line of the previous output:

Shell
tail -n +2

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

Shell
tr -d "*"

Print only the first column:

Shell
awk '{print $1}'

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

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

References