Last active
May 3, 2021 13:48
-
-
Save browny/3839a7227c254749fecc05f2ecffe752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install parallel first (sudo apt-get install -y parallel) | |
JOB_NUM=10 | |
NAME_FILTER='*' | |
# stop instances | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/RUNNING/ {printf "gcloud -q compute instances stop %s --zone %s;\n", $1, $2 > "stop-instances.txt" }' | |
parallel --jobs $JOB_NUM < stop-instances.txt | |
# remove delete protection | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/TERMINATED/ {printf "gcloud -q compute instances update %s --no-deletion-protection --zone %s;\n", $1, $2 > "remove-protection.txt" }' | |
parallel --jobs $JOB_NUM < remove-protection.txt | |
# delete instances | |
gcloud compute instances list --filter=name:$NAME_FILTER | awk '/TERMINATED/ {printf "gcloud -q compute instances delete %s --zone %s;\n", $1, $2 > "delete-instances.txt" }' | |
parallel --jobs $JOB_NUM < delete-instances.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment