-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_terraform.sh
executable file
·342 lines (299 loc) · 11.9 KB
/
run_terraform.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
function terraform_install_check()
{
if ! command -v terraform &> /dev/null
then
echo "terraform CLI binary could not be found"
echo "!!!! Please install Terraform !!!!"
fi
}
function ansible_install_check()
{
if ! command -v ansible &> /dev/null
then
echo "ansible CLI binary could not be found"
echo "!!!! Please install Ansible Core !!!!"
echo "ALT: Please install Ansible Community Edition, which includes Ansible Core and default community Ansible Collections"
fi
}
function terraform_version_check()
{
terraform_version="$(terraform --version | awk 'NR==1{print $2}' | sed 's/v//g')"
# Simple resolution to version comparison: https://stackoverflow.com/a/37939589/8412427
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if [ $(version $terraform_version) -lt $(version "1.0.3") ]; then
echo "Terraform version is $terraform_version"
echo "Lower Terraform version than tested, may produce unexpected results"
fi
}
function ansible_version_check()
{
ansible_version="$(ansible --version | awk 'NR==1{print $3}' | sed 's/]//g')"
# Simple resolution to version comparison: https://stackoverflow.com/a/37939589/8412427
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if [ $(version $ansible_version) -lt $(version "2.11.5") ]; then
echo "Ansible version is $ansible_version"
echo "Lower Ansible version than tested, may produce unexpected results"
fi
}
function sap_solution_scenario_choice()
{
scenario_options=(
"SAP HANA - Install single node"
"SAP S/4HANA - Install single node"
"SAP S/4HANA - Install single node (use Maintenance Planner download)"
"SAP S/4HANA - System Copy single node (Homogeneous with SAP HANA Backup / Recovery)"
"SAP BW/4HANA - Install single node"
"SAP ECC on HANA - Install single node"
"SAP ECC on HANA - System Copy single node (Homogeneous with SAP HANA Backup / Recovery)"
"SAP ECC on IBM DB2 - Install single node"
"SAP ECC on Oracle DB - Install single node"
"SAP ECC on SAP ASE - Install single node"
"SAP ECC on SAP MaxDB - Install single node"
"SAP NetWeaver AS (ABAP) with SAP HANA - Install single node"
"SAP NetWeaver AS (ABAP) with IBM DB2 - Install single node"
"SAP NetWeaver AS (ABAP) with Oracle DB - Install single node"
"SAP NetWeaver AS (ABAP) with SAP ASE - Install single node"
"SAP NetWeaver AS (ABAP) with SAP MaxDB - Install single node"
"SAP NetWeaver AS (JAVA) with IBM DB2 - Install single node"
"SAP NetWeaver AS (JAVA) with SAP ASE - Install single node"
"Quit"
)
select opt_scenario in "${scenario_options[@]}"
do
case $opt_scenario in
"SAP HANA - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_hana_single_node_install"
break
;;
"SAP S/4HANA - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_s4hana_single_node_install"
break
;;
"SAP S/4HANA - Install single node (use Maintenance Planner download)")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_s4hana_single_node_install_maintenance_plan"
break
;;
"SAP S/4HANA - System Copy single node (Homogeneous with SAP HANA Backup / Recovery)")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_s4hana_single_node_system_copy_homogeneous_hdb"
break
;;
"SAP BW/4HANA - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_bw4hana_single_node_install"
break
;;
"SAP ECC on HANA - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_hana_single_node_install"
break
;;
"SAP ECC on HANA - System Copy single node (Homogeneous with SAP HANA Backup / Recovery)")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_hana_single_node_system_copy_homogeneous_hdb"
break
;;
"SAP ECC on IBM DB2 - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_ibmdb2_single_node_install"
break
;;
"SAP ECC on Oracle DB - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_oracledb_single_node_install"
break
;;
"SAP ECC on SAP ASE - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_sapase_single_node_install"
break
;;
"SAP ECC on SAP MaxDB - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_ecc_sapmaxdb_single_node_install"
break
;;
"SAP NetWeaver AS (ABAP) with SAP HANA - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_abap_hana_install"
break
;;
"SAP NetWeaver AS (ABAP) with IBM DB2 - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_abap_ibmdb2_install"
break
;;
"SAP NetWeaver AS (ABAP) with Oracle DB - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_abap_oracledb_install"
break
;;
"SAP NetWeaver AS (ABAP) with SAP ASE - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_abap_sapase_install"
break
;;
"SAP NetWeaver AS (ABAP) with SAP MaxDB - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_abap_sapmaxdb_install"
break
;;
"SAP NetWeaver AS (JAVA) with IBM DB2 - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_java_ibmdb2_install"
break
;;
"SAP NetWeaver AS (JAVA) with SAP ASE - Install single node")
echo ">>> Chosen option $REPLY: $opt_scenario"
sap_solution_scenario="sap_nwas_java_sapase_install"
break
;;
"Quit")
break
;;
*) echo "Invalid option $REPLY";;
esac
done
}
function infrastructure_platform_choice()
{
infrastructure_options=(
"AWS - EC2 instance"
"GCP - Compute Engine Virtual Machine"
"IBM Cloud - Intel Virtual Server"
"IBM Cloud - IBM Power Virtual Server"
"IBM PowerVC - PHYP LPAR"
"MS Azure - Virtual Machine"
# "oVirt - Red Hat Virtualization (RHV)"
"VMware vSphere - Virtual Machine"
"Quit"
)
select opt_infrastructure in "${infrastructure_options[@]}"
do
case $opt_infrastructure in
"AWS - EC2 instance")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="aws_ec2_instance"
break
;;
"GCP - Compute Engine Virtual Machine")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="gcp_ce_vm"
break
;;
"IBM Cloud - Intel Virtual Server")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="ibmcloud_vs"
break
;;
"IBM Cloud - IBM Power Virtual Server")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="ibmcloud_powervs"
break
;;
"IBM PowerVC - PHYP LPAR")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="ibmpowervc"
break
;;
"MS Azure - Virtual Machine")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="msazure_vm"
break
;;
# "oVirt - Red Hat Virtualization (RHV)")
# echo ">>> Chosen option $REPLY: $opt_infrastructure"
# infrastructure_platform="ovirt_rhv"
# break
# ;;
"VMware vSphere - Virtual Machine")
echo ">>> Chosen option $REPLY: $opt_infrastructure"
infrastructure_platform="vmware_vm"
break
;;
"Quit")
break
;;
*) echo "Invalid option $REPLY";;
esac
done
}
function terraform_tfvars_choice()
{
vars_options=(
"No"
"Yes"
"Quit"
)
select opt_variables in "${vars_options[@]}"
do
case $opt_variables in
"No")
echo ">>> Chosen option $REPLY: $opt_variables"
tfvars_enable=0
break
;;
"Yes")
echo ">>> Chosen option $REPLY: $opt_variables"
tfvars_enable=1
break
;;
"Quit")
break
;;
*) echo "Invalid option $REPLY";;
esac
done
}
# Main
terraform_install_check
ansible_install_check
terraform_version_check
ansible_version_check
echo "----"
echo "Choose your SAP solution scenario"
echo "----"
sap_solution_scenario_choice
printf "\n"
echo "----"
echo "Choose your infrastructure platform: Cloud IaaS or Hypervisor"
echo "----"
infrastructure_platform_choice
printf "\n"
echo "----"
echo "Choose whether to use generic Terraform Variables for this execution?"
echo "--> If No: execution will prompt and require value to be entered for each Terraform Variable"
echo "--> If Yes: execution will use tfvars file"
echo "----"
terraform_tfvars_choice
printf "\n"
echo "----"
echo "Starting Terraform for $sap_solution_scenario $infrastructure_platform"
echo "... running terraform init and terraform apply"
echo "----"
printf "\n"
if [ $tfvars_enable = 0 ]; then
cd ./$sap_solution_scenario/$infrastructure_platform
echo "Executing command 'terraform apply'"
terraform init
terraform apply
elif [ $tfvars_enable = 1 ]; then
cd ./$sap_solution_scenario/$infrastructure_platform
terraform init
echo "Using the following generic Terraform Variables:"
echo "----"
cat variables_generic_for_cli.tfvars
printf "\n"
echo "Executing command 'terraform apply -var-file=variables_generic_for_cli.tfvars'"
echo "Prompting for remaining Terraform Variables:"
echo "----"
terraform apply -var-file=variables_generic_for_cli.tfvars
echo "####"
printf "\n"
echo "# Please change your parent shell current directory before executing the SSH commands. Change to the Terraform Template directory:"
echo "cd ./$sap_solution_scenario/$infrastructure_platform"
fi