-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcleanup-gcp.sh
78 lines (64 loc) · 2.09 KB
/
cleanup-gcp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
gcloud config set project $GCLOUD_PROJECT
#delete google storage buckets
for i in $(gsutil ls); do
gsutil rm -r $i &
done;
wait
#delete firewall rules
for i in $(gcloud compute firewall-rules list -r ^oc-.* | awk 'NR>1 {print $1}'); do
gcloud compute firewall-rules delete -q $i &
done;
wait
#delete forwarding rules
for i in $(gcloud compute forwarding-rules list | awk 'NR>1 {print $1}'); do
gcloud compute forwarding-rules delete -q $i --region "us-central1" &
done;
wait
#delete target pools
for i in $(gcloud compute target-pools list | awk 'NR>1 {print $1}'); do
gcloud compute target-pools delete -q $i --region "us-central1" &
done;
wait
#delete static address
for i in $(gcloud compute addresses list | awk 'NR>1 {print $1}'); do
gcloud compute addresses delete -q $i --region "us-central1" &
done;
wait
#delete backend-services
for i in $(gcloud beta compute backend-services list | awk 'NR>1 {print $1}'); do
gcloud beta compute backend-services delete -q $i --region "us-central1" &
done;
wait
#delete health checks
for i in $(gcloud compute health-checks list | awk 'NR>1 {print $1}'); do
gcloud compute health-checks delete -q $i &
done;
wait
#delete instance-groups
for k in us-central1-a us-central1-b us-central1-f; do
for i in $(gcloud compute instance-groups unmanaged list --zones $k | awk 'NR>1 {print $1}'); do
gcloud compute instance-groups unmanaged delete -q $i --zone $k &
done;
done;
wait
#delete VMs
for k in us-central1-a us-central1-b us-central1-f; do
for i in $(gcloud compute instances list --zones $k| awk 'NR>1 {print $1}'); do
gcloud compute instances delete $i -q --zone "$k" &
done;
done;
wait
#delete disks
for k in us-central1-a us-central1-b us-central1-f; do
for i in $(gcloud compute disks list --zones $k | awk 'NR>1 {print $1}'); do
gcloud compute disks delete -q $i --zone $k &
done;
done
wait
#empty but not dns zone (propagation of a new zone is too slow for practical purposes)
touch empty-file
gcloud dns record-sets import -z "$GCLOUD_PROJECT" --delete-all-existing empty-file
rm empty-file
#gcloud dns managed-zones delete "$GCLOUD_PROJECT"