-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathzsec
executable file
·1857 lines (1785 loc) · 91.5 KB
/
zsec
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -eo pipefail
### SET COLOR CODES ###
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
CYAN=$(tput setaf 6)
RESET=$(tput sgr0)
usage()
{
echo "Usage: $0 <up|destroy>"
exit 1
}
if [ $# -ne 1 ] ; then
usage
else
case $1 in
up|destroy|do)
oper=$1
;;
*)
usage
;;
esac
fi
if [[ "$oper" == "up" ]]; then
PS3="${CYAN}Select desired deployment: ${RESET}"
deployments=("greenfield - Recommended for isolated test/POV deployments. Creates new network infrastructure, test workloads, and a public bastion host" "brownfield - Recommended for prod deployments. Bring-your-own existing network infrastructure customizations + no workload/bastion creation")
select deployment in "${deployments[@]}"
do
case $REPLY in
1)
echo "Greenfield deployment selected..."
echo "${YELLOW}**Caution** These deployments include test workloads and publicly accessible bastion hosts and are intended primarily for lab/test environments${RESET}"
echo ""
deployment=greenfield
break
;;
2)
echo "Brownfield deployment selected..."
deployment=brownfield
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
fi
if [[ "$deployment" == "greenfield" ]]; then
PS3="${CYAN}Select desired deployment type: ${RESET}"
dtypes=(
"Deploy 1 Cloud Connector in a new VPC"
"Deploy 1 Cloud Connector in a new VPC with Route 53 rules for ZPA"
"Deploy multiple Cloud Connectors + Gateway Load Balancer in a new VPC"
"Deploy multiple Cloud Connectors + Gateway Load Balancer in a new VPC with Route 53 rules for ZPA"
"Deploy Auto Scaling Cloud Connectors + Gateway Load Balancer in a new VPC"
"Deploy Auto Scaling Cloud Connectors + Gateway Load Balancer in a new VPC with Route 53 rules for ZPA"
"Deploy a new VPC - No Cloud Connector resources"
)
select greenfield_type in "${dtypes[@]}"
do
case $REPLY in
1)
echo "Deployment type base_1cc selected..."
dtype=base_1cc
break
;;
2)
echo "Deployment type base_1cc_zpa selected..."
dtype=base_1cc_zpa
break
;;
3)
echo "Deployment type base_cc_gwlb selected..."
dtype=base_cc_gwlb
break
;;
4)
echo "Deployment type base_cc_gwlb_zpa selected..."
dtype=base_cc_gwlb_zpa
break
;;
5)
echo "Deployment type base_cc_gwlb_asg selected..."
dtype=base_cc_gwlb_asg
break
;;
6)
echo "Deployment type base_cc_gwlb_asg_zpa selected..."
dtype=base_cc_gwlb_asg_zpa
break
;;
7)
echo "Deployment type base selected..."
dtype=base
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
elif [[ "$deployment" == "brownfield" ]]; then
PS3="${CYAN}Select desired deployment type: ${RESET}"
dtypes=(
"Deploy multiple Cloud Connectors + Gateway Load Balancer in a new or existing VPC"
"Deploy Auto Scaling Cloud Connectors + Gateway Load Balancer in a new or existing VPC"
)
select brownfield_type in "${dtypes[@]}"
do
case $REPLY in
1)
echo "Deployment type cc_gwlb selected..."
dtype=cc_gwlb
break
;;
2)
echo "Deployment type cc_gwlb_asg selected..."
dtype=cc_gwlb_asg
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
else
dtype=$dtype
fi
echo "Discovering processor architecture..."
archdetect=$(uname -m)
tversion=1.1.9
echo "Detecting OS..."
if [[ "$OSTYPE" == "linux"* ]]; then
os_str=linux
arch=amd64
ostype=Linux
elif [[ "$OSTYPE" == "darwin"* && $archdetect == "arm64" ]]; then
os_str=darwin
arch=arm64
ostype=MacOS_arm64
elif [[ "$OSTYPE" == "darwin"* ]]; then
os_str=darwin
arch=amd64
ostype=MacOS
elif [[ "$OSTYPE" == "freebsd"* ]]; then
os_str=freebsd
arch=amd64
ostype=FreeBSD
echo "FreeBSD support coming soon..."
exit 1
else
echo "${RED}Unsupported OS: $OSTYPE${RESET}"
exit 1
fi
echo "OS is ${GREEN}$ostype${RESET}"
dir=bin
echo "Creating a local $dir directory if not present..."
if [[ ! -e $dir ]]; then
mkdir $dir
elif [[ ! -d $dir ]]; then
echo "${RED}$dir already exists but is not a directory${RESET}" 1>&2
exit 1
fi
if [[ "$oper" == "up" && ! -e ./.zsecrc ]]; then
first_run="yes"
# AWS Region selection
PS3="${CYAN}Select desired AWS region: ${RESET}"
region_list=(
"af-south-1"
"ap-east-1"
"ap-northeast-1"
"ap-northeast-2"
"ap-northeast-3"
"ap-south-1"
"ap-south-2"
"ap-southeast-1"
"ap-southeast-2"
"ap-southeast-3"
"ap-southeast-4"
"ca-central-1"
"cn-north-1"
"cn-northwest-1"
"eu-central-1"
"eu-central-2"
"eu-north-1"
"eu-south-1"
"eu-south-2"
"eu-west-1"
"eu-west-2"
"eu-west-3"
"il-central-1"
"me-central-1"
"me-south-1"
"sa-east-1"
"us-east-1"
"us-east-2"
"us-gov-east-1"
"us-gov-west-1"
"us-west-1"
"us-west-2"
)
select region_selection in "${region_list[@]}"; do
for region_choice in "${region_list[@]}"; do
if [[ $region_choice == $region_selection ]]; then
aws_region=$region_selection
echo "AWS region ${GREEN}$aws_region${RESET} selected..."
echo "export TF_VAR_aws_region='$aws_region'" > .zsecrc
echo "export AWS_DEFAULT_REGION='$aws_region'" >> .zsecrc
if [[ "$aws_region" == "cn"* ]]; then
aws_partition="aws-cn"
elif [[ "$aws_region" == "us-gov"* ]]; then
aws_partition="aws-us-gov"
else
aws_partition="aws"
fi
break 2
fi
done
done
# AWS Profile Lookup
if [[ ! -e ~/.aws/config ]]; then
echo "No local AWS Configuration file located in ~/.aws/config"
profile_selection="Manually enter AWS Credentials"
else
find_aws_profiles=$(grep '^\[' <~/.aws/config | sed -E 's/\[profile (.*)/\1/g' | sed 's/\[//; s/\]//' )
echo "The following AWS profiles were discovered on this system..."
PS3="${CYAN}Select desired AWS Profile: ${RESET}"
aws_profiles_list=($find_aws_profiles "Manually enter AWS Credentials")
select profile_selection in "${aws_profiles_list[@]}" ; do
for profile_choice in "${aws_profiles_list[@]}"; do
if [[ $profile_choice == $profile_selection ]]; then
break 2
fi
done
done
fi
if [[ $profile_selection == "Manually enter AWS Credentials" ]]; then
echo "Proceeding with manual AWS credentials..."
else
selected_aws_profile=$profile_selection
echo "Setting AWS Profile to $selected_aws_profile"
echo "export AWS_PROFILE='$selected_aws_profile'" >> .zsecrc
fi
# Checking for AWS MFA required
while true; do
read -r -p "${CYAN}Is an AWS MFA session token generation required? (yes/no): ${RESET}" mfa_response
case $mfa_response in
yes|y )
echo "${YELLOW}MFA enabled${RESET}"
mfa_enabled=true
break
;;
no|n )
echo "${YELLOW}MFA not enabled. Proceeding...${RESET}"
mfa_enabled=false
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
# Get MFA session token
if [[ $mfa_enabled == true ]]; then
echo "Gathering information to get AWS Session Token. We need the following details:"
echo "example - arn:$aws_partition:iam::1234567890:mfa/JDoe@company.com where Account ID = 1234567890 and User Account = JDoe@company.com"
read -r -p "${CYAN}Enter AWS Account ID: ${RESET}" aws_account_id
read -r -p "${CYAN}Enter AWS MFA User account: ${RESET}" aws_user_account
echo "unsetting existing AWS Environment variables (unset AWS_SESSION_TOKEN AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY)"
unset AWS_SESSION_TOKEN AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
read -r -p "${CYAN}Enter token code from MFA device: ${RESET}" mfa_token
echo "getting session token (aws sts get-session-token --serial-number arn:$aws_partition:iam::${aws_account_id}:mfa/${aws_user_account} --token-code)"
aws sts get-session-token --serial-number arn:$aws_partition:iam::${aws_account_id}:mfa/${aws_user_account} --token-code ${mfa_token} | tee temp_token.txt
AccessKeyId=$(sed -nr -e '/AccessKeyId/{s/.*"AccessKeyId": "([^"]+)".*/\1/;p;}' temp_token.txt)
SecretAccessKey=$(sed -nr -e '/SecretAccessKey/{s/.*"SecretAccessKey": "([^"]+)".*/\1/;p;}' temp_token.txt)
SessionToken=$(sed -nr -e '/SessionToken/{s/.*"SessionToken": "([^"]+)".*/\1/;p;}' temp_token.txt)
while true; do
read -r -p "${CYAN}Should Terraform use these temporary credentials? [yes/no]: ${RESET}" sts_values_response
case $sts_values_response in
yes|y )
echo "Setting AWS Access Key, Secret Access Key, and Session Token..."
echo "export AWS_ACCESS_KEY_ID='$AccessKeyId'" >> .zsecrc
echo "export AWS_SECRET_ACCESS_KEY='$SecretAccessKey'" >> .zsecrc
echo "export AWS_SESSION_TOKEN='$SessionToken'" >> .zsecrc
echo "${GREEN}Proceeding to deployment configuration...${RESET}"
break
;;
no|n )
echo "Automatic Session Token retrieval failed. Enter AWS credentials manually..."
read -r -p "${CYAN}Enter AWS Access Key ID: ${RESET}" aws_key
echo "You entered: $aws_key"
echo "export AWS_ACCESS_KEY_ID='$aws_key'" >> .zsecrc
read -r -p "${CYAN}Enter AWS Secret Access Key: ${RESET}" aws_secret
echo "You entered: $aws_secret"
echo "export AWS_SECRET_ACCESS_KEY='$aws_secret'" >> .zsecrc
read -r -p "${CYAN}Enter AWS Session Token: ${RESET}" aws_session_token
echo "You entered: $aws_session_token"
echo "export AWS_SESSION_TOKEN='$aws_session_token'" >> .zsecrc
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
rm -f temp_token.txt
elif [[ $mfa_enabled == false && $profile_selection == "Manually enter AWS Credentials" ]]; then
read -r -p "${CYAN}Enter AWS Access Key ID: ${RESET}" aws_key
echo "You entered: $aws_key"
echo "export AWS_ACCESS_KEY_ID='$aws_key'" >> .zsecrc
read -r -p "${CYAN}Enter AWS Secret Access Key: ${RESET}" aws_secret
echo "You entered: $aws_secret"
echo "export AWS_SECRET_ACCESS_KEY='$aws_secret'" >> .zsecrc
fi
if [[ $mfa_enabled == false ]]; then
while true; do
read -r -p "${CYAN}Do you have an AWS Session Token to enter? [yes/no]: ${RESET}" session_token_response
case $session_token_response in
yes|y )
read -r -p "${CYAN}Enter AWS Session Token: ${RESET}" aws_session_token
echo "You entered: $aws_session_token"
echo "export AWS_SESSION_TOKEN='$aws_session_token'" >> .zsecrc
break
;;
no|n )
echo "${YELLOW}Proceeding with no session token...${RESET}"
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
fi
if [[ "$dtype" != "base" ]]; then
PS3="${CYAN}Select your Zscaler Cloud: ${RESET}"
zs_clouds=("zscloud.net" "zscaler.net" "zscalertwo.net" "zscalerthree.net" "zscalerten.net" "zscalergov.net" "zscalerbeta.net" "other")
select zscaler_cloud in "${zs_clouds[@]}"
do
case $REPLY in
1)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
2)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
3)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
4)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
5)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
6)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
7)
echo "Zscaler Cloud ${GREEN}$zscaler_cloud${RESET} selected"
zscaler_cloud=$zscaler_cloud
break
;;
8)
echo "Zscaler Cloud ${YELLOW}$zscaler_cloud${RESET} selected"
while true; do
read -r -p "${CYAN}Enter your desired Zscaler Cloud name (e.g. zscalerbeta.net): ${RESET}" manual_cloud_name_response
case $manual_cloud_name_response in
zspreview|zscalerpreview|preview|zspreview.net|zscalerpreview.net|preview.net )
echo "Setting zspreview.net"
zscaler_cloud=zspreview.net
zs_env=development
break
;;
zsdevel|zscalerdevel|devel|zsdevel.net|zscalerdevel.net|devel.net )
echo "Setting zsdevel.net"
zscaler_cloud=zsdevel.net
zs_env=development
break
;;
zsqa|zscalerqa|qa|zsqa.net|zscalerqa.net|qa.net )
echo "Setting zsqa.net"
zscaler_cloud=zsqa.net
zs_env=development
break
;;
*)
echo "${RED}Invalid response. Please enter a valid Zscaler Cloud name${RESET}"
esac
done
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
echo "export zscaler_cloud='$zscaler_cloud'" >> .zsecrc
fi
if [[ "$deployment" == "greenfield" ]]; then
while true; do
clientpublicip=$(curl -s ifconfig.me)
echo "greenfield deployments include a publicly accessible ssh bastion host.."
read -r -p "${CYAN}Your current public IP is ${clientpublicip}. Restrict SSH access to only this IP address? [yes/no]: ${RESET}" bastion_response
case $bastion_response in
yes|y )
echo "Updating Bastion security group to permit SSH only from ${GREEN}${clientpublicip}${RESET}: "
echo "export TF_VAR_bastion_nsg_source_prefix='[\"${clientpublicip}/32\"]'" >> .zsecrc
useclientip=true
break
;;
no|n )
useclientip=false
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
if [[ "$useclientip" == "false" ]]; then
while true; do
read -r -p "${CYAN}Restrict SSH access to a different IP address or range? Default is no meaning permit all [yes/no]: ${RESET}" changebastionip
case $changebastionip in
yes|y )
read -r -p "${CYAN}Enter new IP Address/range w/ CIDR (e.g. 2.2.2.2/32): ${RESET}" bastionipinput
echo "export TF_VAR_bastion_nsg_source_prefix='[\"${bastionipinput}\"]'" >> .zsecrc
if [[ $bastionipinput =~ ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[1-9]))$ ]]
then
echo "${GREEN}$bastionipinput - IP/Netmask valid${RESET}"
else
echo "${RED}$bastionipinput is not valid IP CIDR format${RESET}"
echo "${YELLOW}Delete .zsecrc file and re-run zsec up...${RESET}"
exit 1
fi
break
;;
no|n )
echo "${YELLOW}**Caution** SSH access permitted for all IP addresses...${RESET}"
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
fi
fi
if [[ "$dtype" != "base" ]]; then
# Cloud Connector Size Selection
if [[ "$dtype" != *"asg"* ]]; then
PS3="${CYAN}Select desired Cloud Connector Instance Size: ${RESET}"
cc_sizes=("small" "medium" "large")
select cc_instance_size in "${cc_sizes[@]}"
do
case $REPLY in
1)
echo "Cloud Connector size: ${GREEN}${cc_instance_size}${RESET}"
echo "export TF_VAR_cc_instance_size=${cc_instance_size}" >> .zsecrc
cc_instance_size=${cc_instance_size}
break
;;
2)
echo "Cloud Connector size: ${GREEN}${cc_instance_size}${RESET}"
echo "export TF_VAR_cc_instance_size=${cc_instance_size}" >> .zsecrc
cc_instance_size=${cc_instance_size}
break
;;
3)
echo "Cloud Connector size: ${GREEN}${cc_instance_size}${RESET}"
echo "export TF_VAR_cc_instance_size=${cc_instance_size}" >> .zsecrc
cc_instance_size=${cc_instance_size}
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
elif [[ "$dtype" == *"asg"* ]]; then
echo "${YELLOW}Auto Scaling deployment type identified. Only small CC instance sizes are currently supported. Make sure that the CC provisioning template specified has small selected...${RESET}"
echo "${GREEN}Setting cc_instance_size to small${RESET}"
echo "export TF_VAR_cc_instance_size=small" >> .zsecrc
cc_instance_size=small
fi
# AWS EC2 type selection
PS3="${CYAN}Select AWS EC2 instance type for $cc_instance_size Cloud Connector: ${RESET}"
if [[ "$cc_instance_size" == "small" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.large - Recommended"
"t3.medium - Not recommended for production use"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}c6in.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6in.large'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}c6in.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='t3.medium'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
elif [[ "$aws_region" == "cn-"* ]]; then
vm_sizes=(
"m6i.large - Recommended"
"c6i.large"
"t3.medium - Not recommended for production use"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.large'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}c6i.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6i.large'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}t3.medium${RESET}"
echo "export TF_VAR_ccvm_instance_type='t3.medium'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
else
vm_sizes=(
"m6i.large - Recommended"
"m5n.large"
"c6i.large"
"c6in.large"
"t3.medium - Not recommended for production use"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.large'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
5)
echo "CC EC2 type: ${GREEN}t3.medium${RESET}"
echo "export TF_VAR_ccvm_instance_type='t3.medium'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
fi
elif [[ "$cc_instance_size" == "medium" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
elif [[ "$aws_region" == "cn-"* ]]; then
vm_sizes=(
"m6i.4xlarge - Recommended"
"c6i.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}c6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
else
vm_sizes=(
"m6i.4xlarge - Recommended"
"m5n.4xlarge"
"c6i.4xlarge"
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
fi
elif [[ "$cc_instance_size" == "large" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
elif [[ "$aws_region" == "cn-"* ]]; then
vm_sizes=(
"m6i.4xlarge - Recommended"
"c6i.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}c6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
else
vm_sizes=(
"m6i.4xlarge - Recommended"
"m5n.4xlarge"
"c6i.4xlarge"
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
fi
fi
read -r -p "${CYAN}Enter CC Provisioning URL${RESET} (E.g. connector.zscaler.net/api/v1/provUrl?name=aws_prov_url): " cc_vm_prov_url
echo "Provisioning URL entered is: ${GREEN}$cc_vm_prov_url${RESET}. ${YELLOW}Make sure this matches the CC Instance Size $cc_instance_size chosen${RESET}"
echo "export TF_VAR_cc_vm_prov_url=${cc_vm_prov_url}" >> .zsecrc
read -r -p "${CYAN}Enter AWS Secrets Manager Secret Name from Secrets Manager${RESET} (E.g ZS/CC/credentials/aws_cc_secret_name): " secret_name
echo "Secret Manager name entered is: ${GREEN}$secret_name${RESET}"
echo "export TF_VAR_secret_name=${secret_name}" >> .zsecrc
http_probe_port_default=50000
read -r -p "${CYAN}Enter CC service HTTP health probe port number. Valid input = 80 or any number between 1024-65535 [Default=$http_probe_port_default]: ${RESET}" http_probe_port_input
http_probe_port=${http_probe_port_input:-$http_probe_port_default}
if ((http_probe_port == 80 || http_probe_port >= 1024 && http_probe_port <= 65535)); then
echo "Valid HTTP probe port input of ${GREEN}$http_probe_port${RESET}"
echo "export TF_VAR_http_probe_port=${http_probe_port}" >> .zsecrc
else
echo "${RED}Invalid HTTP probe port value${RESET}"
echo "${YELLOW}Delete .zsecrc file and re-run zsec up...${RESET}"
exit 1
fi
cc_count_default=2
if [[ "$dtype" == "base_1"* ]]; then
echo "${GREEN}${dtype} will deploy one Cloud Connector in ${aws_region}${RESET}"
elif [[ "$dtype" == "base_2"* || "$dtype" == "cc_ha" ]]; then
echo "${GREEN}${dtype} will deploy two Cloud Connectors in ${aws_region}${RESET}"
elif [[ "$dtype" == *"asg"* ]]; then
echo "Autoscaling deployment type identified. Proceeding to ASG configurations..."
elif [[ "$dtype" == *"gwlb"* ]]; then
read -p "${CYAN}Enter how many Cloud Connectors to deploy? [Default=$cc_count_default]: ${RESET}" cc_count_input
cc_count=${cc_count_input:-$cc_count_default}
if ((cc_count >= 1 && cc_count <= 20)); then
echo "Terraform will deploy ${GREEN}${cc_count} Cloud Connectors${RESET} in ${aws_region}"
echo "export TF_VAR_cc_count=${cc_count}" >> .zsecrc
else
echo "${RED}Invalid cc_count value. Must be a number between 1 and 20${RESET}"
echo "${YELLOW}Delete .zsecrc file and re-run zsec up...${RESET}"
exit 1
fi
fi
if [[ "$dtype" == "base_1"* ]]; then
echo "${GREEN}${dtype} will deploy resources in one Availability Zone subnet in $aws_region${RESET}"
echo "export TF_VAR_az_count=1" >> .zsecrc
else
# AWS number of Availability Zones selection
PS3="${CYAN}Select how many Availability Zone subnets to deploy across: ${RESET}"
zones_list=("1 availability zone" "2 availability zones" "3 availability zones")
select zone_selection in "${zones_list[@]}"
do
case $REPLY in
1 )
if [[ "$dtype" == *"asg"* ]]; then
az_count=1
echo "Terraform will deploy ${GREEN}$az_count Auto Scaling Group${RESET} in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
echo "export TF_VAR_zonal_asg_enabled=true" >> .zsecrc
zonal_asg=true
else
az_count=1
echo "Terraform will deploy ${GREEN}$cc_count Cloud Connectors across $az_count Availability Zone subnets${RESET} in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
fi
break
;;
2 )
az_count=2
echo "Terraform will create ${GREEN}$az_count Availability Zone subnets${RESET}"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
break
;;
3 )
az_count=3
echo "Terraform will create ${GREEN}$az_count Availability Zone subnets${RESET}"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
break
;;
* ) echo "${RED}Invalid response. Please enter a number selection${RESET}";;
esac
done
fi
# Prompt for GWLB Cross-Zone LB enablement
if [[ "$dtype" == *"gwlb"* && "$az_count" > 1 ]]; then
while true; do
read -r -p "${CYAN}Enable GWLB cross-zone load balancing? (yes/no): ${RESET}" cross_zone_lb_enabled
case $cross_zone_lb_enabled in
yes|y )
echo "Cross-zone load balancing ${GREEN}enabled${RESET}"
echo "export TF_VAR_cross_zone_lb_enabled=true" >> .zsecrc
cross_zone_lb=true
break
;;
no|n )
echo "Cross-zone load balancing ${GREEN}disabled${RESET}"
echo "export TF_VAR_cross_zone_lb_enabled=false" >> .zsecrc
cross_zone_lb=false
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
fi
# If Auto Scaling, prompt for how many ASGs to create
if [[ "$dtype" == *"asg"* && "$az_count" > 1 ]]; then
while true; do
if [[ "$cross_zone_lb" == "true" ]]; then
echo "With cross-zone load balancing enabled, it is recommended to deploy a single Auto Scaling Group spanning all $az_count zones"
read -r -p "${CYAN}Deploy all resources in a single Auto Scaling Group? [yes/no]: ${RESET}" zonal_asg_response
elif [[ "$cross_zone_lb" == "false" ]]; then
echo "With cross-zone load balancing disabled, it is recommended to deploy separate Auto Scaling Groups per Availability Zone"
read -r -p "${CYAN}Deploy $az_count separate Auto Scaling Groups? [yes/no]: ${RESET}" zonal_asg_response
fi
case $zonal_asg_response in
yes|y )
if [[ "$cross_zone_lb" == "true" ]]; then
echo "Terraform will deploy ${GREEN}one Auto Scaling Group${RESET} containing $az_count AZs in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
echo "export TF_VAR_zonal_asg_enabled=false" >> .zsecrc
zonal_asg=false
elif [[ "$cross_zone_lb" == "false" ]]; then
echo "Terraform will deploy ${GREEN}$az_count Auto Scaling Groups${RESET} in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
echo "export TF_VAR_zonal_asg_enabled=true" >> .zsecrc
fi
break
;;
no|n )
if [[ "$cross_zone_lb" == "false" ]]; then
echo "Terraform will deploy ${GREEN}one Auto Scaling Group${RESET} containing $az_count AZs in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
echo "export TF_VAR_zonal_asg_enabled=false" >> .zsecrc
zonal_asg=false
elif [[ "$cross_zone_lb" == "true" ]]; then
echo "Terraform will deploy ${GREEN}$az_count Auto Scaling Groups${RESET} in $aws_region"
echo "export TF_VAR_az_count=$az_count" >> .zsecrc
echo "export TF_VAR_zonal_asg_enabled=true" >> .zsecrc
fi
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
fi
min_size_default=2
while [[ "$dtype" == *"asg"* ]]; do
if [[ "$zonal_asg" == true ]]; then
read -r -p "${CYAN}Enter the minimum number of Cloud Connectors to maintain per each Auto Scaling Group [Default=$min_size_default]: ${RESET}" min_size_input
else
read -r -p "${CYAN}Enter the minimum number of Cloud Connectors to maintain in the Auto Scaling Group [Default=$min_size_default]: ${RESET}" min_size_input
fi
min_size=${min_size_input:-$min_size_default}
case $min_size in
1|2|3|4|5|6|7|8|9|10)
echo "Cloud Connector Minimum size: ${GREEN}${min_size}${RESET}"
echo "export TF_VAR_min_size=${min_size}" >> .zsecrc
break
;;
*)
echo "${RED}Invalid ASG Minimum size: ${min_size}. Enter a number 1-10${RESET}"
;;
esac
done
max_size_default=4
while [[ "$dtype" == *"asg"* ]]; do
if [[ "$zonal_asg" == true ]]; then
read -r -p "${CYAN}Enter the maximum number of Cloud Connectors to maintain per each Auto Scaling Group [Default=$max_size_default]: ${RESET}" max_size_input
else
read -r -p "${CYAN}Enter the maximum number of Cloud Connectors to maintain in the Auto Scaling Group [Default=$max_size_default]: ${RESET}" max_size_input
fi
max_size=${max_size_input:-$max_size_default}
if [[ "$max_size" -lt "$min_size" ]]; then
echo "${YELLOW}Max size must be greater than or equal to ${min_size}${RESET}"
else
case $max_size in
1|2|3|4|5|6|7|8|9|10)
echo "Cloud Connector Maximum size: ${GREEN}${max_size}${RESET}"
echo "export TF_VAR_max_size=${max_size}" >> .zsecrc
break
;;
*)
echo "${RED}Invalid ASG Maximum size: ${max_size}. Enter a number 1-10${RESET}"
;;
esac
fi
done
# Prompt for EBS encryption enablement
while true; do
read -r -p "${CYAN}Enable EBS volume encryption? (yes/no) Recommendation is yes: ${RESET}" ebs_encryption_response
case $ebs_encryption_response in
yes|y )
echo "EBS encryption will be ${GREEN}enabled${RESET}"
echo "export TF_VAR_ebs_encryption_enabled=true" >> .zsecrc
ebs_encryption_enabled=true
break
;;
no|n )
echo "EBS encryption will be ${YELLOW}disabled${RESET}"
echo "export TF_VAR_ebs_encryption_enabled=false" >> .zsecrc
ebs_encryption_enabled=false
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
if [[ "$ebs_encryption_enabled" == true ]]; then
echo "Amazon EBS automatically creates a unique AWS managed key in each Region. By default, Amazon EBS uses this KMS key for encryption"
while true; do
read -r -p "${CYAN}Use your own customer managed KMS key instead? (yes/no): ${RESET}" byo_kms_key_response
case $byo_kms_key_response in
yes|y )
read -r -p "${CYAN}Enter KMS key alias (e.g. alias/key_name): ${RESET}" byo_kms_key_alias
echo "Using custom KMS key alias: ${GREEN}$byo_kms_key_alias${RESET}"
echo "export TF_VAR_byo_kms_key_alias=$byo_kms_key_alias" >> .zsecrc
break
;;
no|n )
echo "${GREEN}Using default Amazon KMS key...${RESET}"
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
fi
# Custom GWLB configuration options
if [[ "$dtype" == *"gwlb"* ]]; then
while true; do
read -r -p "${CYAN}Enable GWLB target failover rebalance for existing flows? (yes/no) Recommendation is yes: ${RESET}" rebalance_enabled
case $rebalance_enabled in
yes|y )
echo "GWLB target failover rebalance ${GREEN}enabled${RESET}"
echo "export TF_VAR_rebalance_enabled=true" >> .zsecrc
break
;;
no|n )
echo "GWLB target failover rebalance ${GREEN}disabled${RESET}"
echo "export TF_VAR_rebalance_enabled=false" >> .zsecrc
break
;;
* ) echo "${RED}Invalid response. Please enter yes or no${RESET}";;
esac
done
PS3="${CYAN}Select desired GWLB flow stickiness: ${RESET}"