-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.sh
More file actions
executable file
·41 lines (39 loc) · 1.18 KB
/
template.sh
File metadata and controls
executable file
·41 lines (39 loc) · 1.18 KB
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
#!/bin/bash
#
# What I inherit:
# Variables: VPCID TAG REGION AZLIST STARTED VPCSUBNET
#
APPNET="0"
WHICHROUTE="int"
APP="nat"
if [ -z $STARTED ]; then
echo "Please don't run me directly."
exit 1
fi
for AZ in $AZLIST; do
case $AZ in
a)
NETWORK=10.${VPCSUBNET}.${APPNET}.0/25
AZONE=us-west-2${AZ}
;;
b)
NETWORK=10.${VPCSUBNET}.${APPNET}.128/25
AZONE=us-west-2${AZ}
;;
c)
NETWORK=10.${VPCSUBNET}.${APPNET}.0/24
AZONE=us-west-2${AZ}
;;
*)
echo "I do not know how to proceed with availability zone $AZ"
exit 1
;;
esac
SUBNETID=$(../bin/ec2-describe-subnets -F "tag:region=${REGION}" -F "tag:environment=${TAG}" -F "tag:az=${AZ}" -F "tag:app=${APP}" --hide-tags |awk '{print $2}')
if [ -z $SUBNETID ];then
SUBNETID=$(../bin/ec2-create-subnet -c $VPCID -i "$NETWORK" -z $AZONE |awk '{print $2}')
../bin/ec2-create-tags $SUBNETID --tag environment=${TAG} --tag region=${REGION} --tag az=${AZ} --tag app=${APP}
fi
ROUTETBL=$(../bin/ec2-describe-route-tables -F"tag:environment=${TAG}" -F"tag:access=${WHICHROUTE}" -F"tag:region=${REGION}" -F"tag:az=${AZ}" --hide-tags|grep 'rtb-' |awk '{print $2}')
../bin/ec2-associate-route-table $ROUTETBL -s $SUBNETID
done