forked from Elastifile/gcp-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_google_ilb.sh
executable file
·53 lines (47 loc) · 1.56 KB
/
update_google_ilb.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
#!/bin/bash
set -ux
#impliment command-line options
usage() {
cat << E_O_F
Usage:
-a list of node ips
-e service email
-p project
example: update_google_ilb.sh -a 10.0.0.1,10.0.0.2 -e <service account> -p <project id>
E_O_F
exit 1
}
#variables
LOG="update_google_ilb.log"
CLUSTER_NAME=`terraform show | grep reference_name | cut -d " " -f 5`
while getopts "h?:a:e:p:" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
a) IPS=${OPTARG}
;;
e) SERVICE_EMAIL=${OPTARG}
;;
p) PROJECT=${OPTARG}
;;
esac
done
echo "CLUSTER_NAME: $CLUSTER_NAME" | tee -a ${LOG}
echo "IPS: $IPS" | tee -a ${LOG}
# Configure Google Internal Load Balancer
function update_google_ilb {
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "Updating Load Balancer Instance Group"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
for ip in ${IPS//,/ }; do
instance_name=`gcloud compute instances list --filter="($ip)" --account=$SERVICE_EMAIL --project=$PROJECT | grep -v NAME | awk '{ print $1 }'`
instance_zone=`gcloud compute instances list --filter="($ip)" --account=$SERVICE_EMAIL --project=$PROJECT | grep -v NAME | awk '{ print $2 }'`
instance_group="$CLUSTER_NAME-$instance_zone"
gcloud compute instance-groups unmanaged add-instances $instance_group --instances $instance_name --zone $instance_zone --account=$SERVICE_EMAIL --project=$PROJECT
echo "$instance_name $instance_zone $instance_group"
done
}
# Main
update_google_ilb