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:
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
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:
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):
pulumi stack lsStart at the second line of the previous output:
tail -n +2Delete all occurrences of *. There is a * character next to the currently selected stack and we need to remove this:
tr -d "*"Print only the first column:
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.
while read -r stack; do pulumi stack rm -y "$stack"; done;