-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.sh
executable file
·160 lines (108 loc) · 3.38 KB
/
setup.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
# AWS profile used to differentiate between accounts
profile=$1
menu () {
echo "---------------------------------------------------------------------------------------"
echo "AWS VAULT REFERENCE INSTALLATION"
echo "---------------------------------------------------------------------------------------"
echo ""
echo "Select from the following options..."
echo ""
cat << _EOF_
1. VALIDATE CLOUDFORMATION TEMPLATES
2. BUILD CLOUDFORMATION STACK
0. Quit
_EOF_
echo ""
read -n 1 -p "Enter Selection [0-2] > "
if [[ $REPLY =~ ^[0-2]$ ]]; then
echo ""
case $REPLY in
1)
validate_cf
footer
;;
2)
create_cf_stack
footer
;;
0)
clear
;;
esac
else
echo "** An Invalid Option Has Been Pressed **"
sleep 5
fi
}
footer () {
cat << _EOF_
---------------------------------------------------------------------------------------
PRESS: '0' to Exit | '1' for Menu
---------------------------------------------------------------------------------------
_EOF_
read -n1 -p " > "
echo ""
if [[ $REPLY =~ ^[0-2]$ ]]; then
case $REPLY in
1)
clear
menu
;;
0)
clear
exit
;;
esac
else
echo "*** An Invalid Option Has Been Pressed or Entered ***"
sleep 5
fi
}
validate_cf () {
clear
echo "---------------------------------------------------------------------------------------"
echo "VALIDATE CLOUDFORMATION TEMPLATES"
echo "---------------------------------------------------------------------------------------"
echo ""
echo "Checking Cloudformation Templates - Remedy any errors that appear before attempting to build the stack."
echo ""
sleep 5
echo "Checking Network Template..."
echo ""
aws cloudformation validate-template --template-body file://vault-core-networking.json
echo ""
echo "Checking Security Template..."
echo ""
aws cloudformation validate-template --template-body file://vault-core-security.json
echo ""
echo "Checking Security Template..."
echo ""
aws cloudformation validate-template --template-body file://vault-core-instances.json
}
create_cf_stack () {
clear
echo "---------------------------------------------------------------------------------------"
echo "BUILD CLOUDFORMATION STACK"
echo "---------------------------------------------------------------------------------------"
echo ""
echo "Enter the name of the AWS profile you wish to use (Leave blank for 'default' profile)..."
echo ""
read -p "> " profile
if [ -z "$profile" ]; then
profile="default"
fi
echo ""
echo "Enter the name of the Cloudformation Stack..."
echo ""
read -p "> " stackname
stackname_parsed=$(echo $stackname | tr ' ' '-')
echo ""
aws cloudformation create-stack --stack-name $stackname_parsed"-1" --template-body file://vault-core-networking.json --parameters file://vault-core-networking-parameters.json --capabilities CAPABILITY_IAM
sleep 200
aws cloudformation create-stack --stack-name $stackname_parsed"-2" --template-body file://vault-core-security.json --parameters ParameterKey=VaultStackName,ParameterValue=$stackname_parsed"-1" --capabilities CAPABILITY_IAM
sleep 100
aws cloudformation create-stack --stack-name $stackname_parsed"-3" --template-body file://vault-core-instances.json --parameters ParameterKey=VaultChildStackName,ParameterValue=$stackname_parsed"-2" --capabilities CAPABILITY_IAM
}
clear
menu