Skip to content

Instantly share code, notes, and snippets.

@ellisbrown
Created April 5, 2024 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellisbrown/67e143d79dc4f114ed0d39b04d0d2328 to your computer and use it in GitHub Desktop.
Save ellisbrown/67e143d79dc4f114ed0d39b04d0d2328 to your computer and use it in GitHub Desktop.
Delete all suspended TPUs in a GCP project
#!/bin/bash
PROJECT=my-project
ZONE=us-central2-b
# Print the list of TPU resources in any state
gcloud alpha compute tpus queued-resources list \
--project $PROJECT \
--zone $ZONE
echo # Add a blank line for readability
# List all TPU resources in suspended or failed state and extract their names
SUSPENDED=$(gcloud alpha compute tpus queued-resources list \
--project $PROJECT \
--zone $ZONE | awk '$NF=="SUSPENDED" || $NF=="FAILED"{print $1}')
# If no resources are in suspended state, exit
if [ -z "$SUSPENDED" ]; then
echo "No TPU VMs in suspended state."
exit 0
fi
# Loop through each suspended resource and delete it
for NAME in $SUSPENDED; do
echo "Deleting TPU VM: $NAME"
gcloud alpha compute tpus queued-resources delete $NAME --project $PROJECT --zone $ZONE --quiet
done
echo "Deletion process completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment