-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp-cleanup.sh
executable file
·52 lines (41 loc) · 921 Bytes
/
gcp-cleanup.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
#! /bin/bash
set -e
function bucket_name_tf_state() {
local gcpproject=$1
echo "${gcpproject}-terraform-state"
}
function bucket_name_logging() {
local gcpproject=$1
echo "${gcpproject}-logging"
}
function delete_project_and_buckets() {
local gcpproject=$1
bucket_name_tf_state="$(bucket_name_tf_state "${gcpproject}")"
bucket_name_logging="$(bucket_name_logging "${gcpproject}")"
gcloud storage buckets delete gs://"${bucket_name_tf_state}"
gcloud storage buckets delete gs://"${bucket_name_logging}"
gcloud projects delete "${gcpproject}" --quiet
}
##
## Script
##
gcpproject=""
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
usage
;;
--gcpproject)
gcpproject="$2"
shift
;;
*)
usage "Unknown option '$1'"
;;
esac
shift
done
if [ "${gcpproject}" == "" ]; then
usage "GCP project name must be provided"
fi
delete_project_and_buckets "${gcpproject}"