-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzs_cc_cf_template_asg_gwlb.yaml
1163 lines (1123 loc) · 41 KB
/
zs_cc_cf_template_asg_gwlb.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Description: Zscaler Cloud Connector Starter Deployment Template with Auto Scaling and GWLB v1.3.3
Metadata:
LICENSE: 'Apache License, Version 2.0'
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Network Configuration
Parameters:
- NetworkVpcId
- NetworkAvailabilityZones
- NetworkCcSubnetIds
- AsgZonalEnabled
- Label:
default: Zscaler Launch Template Configuration
Parameters:
- ZscalerOsAmi
- ZscalerKeyPairName
- ZscalerCcInstanceProfile
- ZscalerCloudTagsEnabled
- ZscalerSupportServerRuleEnabled
- ZscalerCcMgmtIntfSecurityGroup
- ZscalerCcSrvcIntfSecurityGroup
- ZscalerSecretManagerSecretName
- ZscalerCcInstanceSize
- ZscalerAwsEc2InstanceType
- ZscalerCloudConnectorProvUrl
- ZscalerHttpProbePort
- ZscalerEBSEncryptionEnabled
- Label:
default: Auto Scaling Group Configuration
Parameters:
- AsgS3BucketName
- AsgS3Key
- AsgMinSize
- AsgMaxSize
- AsgLaunchTemplateVersion
- AsgWarmPoolReuseOnScaleIn
- AsgTargetTrackingMetric
- AsgTargetCpuUtilValue
- AsgWarmPoolEnabled
- AsgWarmPoolState
- AsgWarmPoolMinSize
- AsgWarmPoolMaxGroupPreparedCapacity
- AsgLogGroupRetentionInDays
- Label:
default: Gateway Load Balancer Configuration
Parameters:
- GwlbTargetGroupRebalanceOnDeregistrationOrUnhealthy
- GwlbFlowStickiness
- GwlbCrossZoneLbEnabled
- GwlbVpcEpSubnetIds
- GwlbVpcEpServicePrincipals
- GwlbAcceptanceRequiredVpcEps
ParameterLabels:
NetworkVpcId:
default: VPC ID
NetworkAvailabilityZones:
default: Choose Availability Zones to Deploy Zscaler Cloud Connector Resources
NetworkCcSubnetIds:
default: Subnet IDs for the Zscaler Cloud Connector Auto Scaling Group
AsgLaunchTemplateVersion:
default: Auto Scaling Group Launch Template Version
AsgMinSize:
default: Auto Scaling Group Minimum Size
AsgMaxSize:
default: Auto Scaling Group Maximum Size
AsgWarmPoolReuseOnScaleIn:
default: Auto Scaling Group Reuse Instances on Scale In
AsgTargetCpuUtilValue:
default: Auto Scaling Group Target CPU Utilization Value
AsgWarmPoolEnabled:
default: Auto Scaling Group Warm Pool Enabled
AsgWarmPoolState:
default: Auto Scaling Group Warm Pool State
AsgWarmPoolMinSize:
default: Auto Scaling Group Warm Pool Minimum Size
AsgWarmPoolMaxGroupPreparedCapacity:
default: Auto Scaling Group Warm Pool Max Group Prepared Capacity
AsgLogGroupRetentionInDays:
default: Log Group Retention
AsgS3BucketName:
default: Lambda S3 Bucket Name
AsgS3Key:
default: Lambda S3 Key
AsgZonalEnabled:
default: Availability Zone based Auto Scaling Groups
GwlbAcceptanceRequiredVpcEps:
default: Require Acceptance For Newly Created VPC Endpoints?
GwlbCrossZoneLbEnabled:
default: Enable Cross-Zone Load Balancing
GwlbTargetGroupRebalanceOnDeregistrationOrUnhealthy:
default: GWLB Target Failover Rebalance Strategy
GwlbFlowStickiness:
default: GWLB Flow Stickiness Strategy
GwlbVpcEpServicePrincipals:
default: VPC Endpoint Service Principals
GwlbVpcEpSubnetIds:
default: VPC Endpoint Subnets to Create VPC Endpoints in (one per AZ)
ZscalerHttpProbePort:
default: HTTP Monitor Probe Port
ZscalerKeyPairName:
default: Zscaler Cloud Connector Instance Key Pair
ZscalerSecretManagerSecretName:
default: Secrets Manager Secret Name
ZscalerAwsEc2InstanceType:
default: Zscaler Cloud Connector AWS EC2 Instance Type
ZscalerCcInstanceProfile:
default: Existing IAM Role ARN to use for Zscaler Cloud Connector
ZscalerCloudTagsEnabled:
default: Add IAM Policy Permissions for AWS Tag Collection. Only enforced if CFT creates a new IAM Role
ZscalerSupportServerRuleEnabled:
default: Add Management Security Group Rule for Zscaler Support Server Connectivity
ZscalerCcInstanceSize:
default: Zscaler Cloud Connector Instance Size
ZscalerCcMgmtIntfSecurityGroup:
default: Existing Security Group ID to use for Zscaler Cloud Connector Management Interface
ZscalerCcSrvcIntfSecurityGroup:
default: Existing Security Group ID to use for Zscaler Cloud Connector Service Interface
ZscalerCloudConnectorProvUrl:
default: Cloud Connector Provisioning URL
ZscalerOsAmi:
default: Zscaler Cloud Connector AMI
ZscalerEBSEncryptionEnabled:
default: EBS Encryption Enabled
cfn-lint:
config:
ignore_checks:
- E9007
- W4001
- W7001
- W8001
- E2507
- E2522
- E6002
- W2001
- E3003
- E2523
- W8003
- W1020 #Fn::Sub isn't needed because there are no variables at Resources/
- W2030 # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html#cfn-logs-loggroup-retentionindays
- E3510 # resource ID of secrets manager inputted from macro transform
- E3014 # subnet mappings inputted from macro transform
Transform:
- Name: ZSCC-Macro
Parameters:
operation : ZSCCASG
Parameters:
NetworkVpcId:
Description: "The VPC ID where you want to deploy your Cloud Connector Instances"
Type: 'AWS::EC2::VPC::Id'
NetworkAvailabilityZones:
Type: List<AWS::EC2::AvailabilityZone::Name>
Description: "A list of desired Availability Zones to deploy Zscaler Cloud Connector/ASG, GWLB, and VPC Endpoints"
NetworkCcSubnetIds:
Description: "The subnets where the Zscaler Cloud Connector Auto Scaling Group is deployed."
Type: List<AWS::EC2::Subnet::Id>
# AsgLaunchTemplateVersion:
# Type: String
# Description: >-
# Launch template version. Can be version number, \"$Latest\" (default) or \"$Default\"
# AllowedPattern: '^(\$Latest|\$Default|[0-9]+)$'
# Default: "$Latest"
AsgZonalEnabled:
Type: String
Description: "Select \"true\" to create one ASG per AZ (default), else \"false\" to create a single ASG spanning all selected AZs"
Default: true
AllowedValues:
- true
- false
AsgMinSize:
Type: Number
MinValue: 1
MaxValue: 10
ConstraintDescription: >-
Healthy Threshold: Minimum 1 and maximum 10
Description: >-
Minimum number of Cloud Connectors to maintain in Autoscaling group
Default: 2
AsgMaxSize:
Type: Number
MinValue: 1
MaxValue: 10
ConstraintDescription: >-
Healthy Threshold: Minimum 1 and maximum 10
Description: >-
Maximum number of Cloud Connectors to maintain in Autoscaling group
Default: 4
AsgTargetCpuUtilValue:
Type: Number
Description: >-
Target value number for autoscaling policy CPU utilization target tracking.
ie: trigger a scale in/out to keep average CPU Utliization percentage across all instances at/under this number
Default: 80
AsgWarmPoolEnabled:
Type: String
Description: "Select \"true\" to enable Auto Scaling Group warm pool (default), else \"false\""
Default: true
AllowedValues:
- true
- false
AsgWarmPoolReuseOnScaleIn:
Type: String
Description: "Select \"true\" to enable Auto Scaling Group reuse instance on scale-in, else \"false\" (default)"
Default: false
AllowedValues:
- true
- false
AsgWarmPoolState:
Type: String
Description: >-
Sets the instance state to transition to after the lifecycle hooks finish.
Valid values are: Stopped (default), Running or Hibernated.
Ignored when 'Auto Scaling Group Warm Pool Enabled' is No
Default: "Stopped"
AllowedValues:
- "Stopped"
- "Running"
AsgWarmPoolMaxGroupPreparedCapacity:
Type: Number
MinValue: -1
MaxValue: 10
ConstraintDescription: >-
Healthy Threshold: Minimum -1 and maximum 10
Default: -1
Description: >-
Specifies the total maximum number of instances that are allowed to be in the warm pool or in any state except Terminated for the Auto Scaling group.
Specify it only if you do not want the warm pool size to be determined by the difference between the group's maximum capacity and its desired capacity.
Ignored when 'Auto Scaling Group Warm Pool Enabled' is No
AsgWarmPoolMinSize:
Type: Number
MinValue: 0
MaxValue: 10
ConstraintDescription: >-
Healthy Threshold: Minimum 0 and maximum 10
Default: 0
Description: >-
Specifies the minimum number of instances to maintain in the warm pool.
This helps you to ensure that there is always a certain number of warmed instances available to handle traffic spikes.
Ignored when 'Auto Scaling Group Warm Pool Enabled' is No
AsgS3BucketName:
Type: String
AllowedPattern: ^[0-9a-zA-Z]+([0-9a-zA-Z-]*[0-9a-zA-Z])*$
Description: AWS S3 Bucket name in this region where lambda deployment package zip file exists
AsgS3Key:
Type: String
AllowedPattern: ^[0-9a-zA-Z-/_\.\s]*.zip$
Description: AWS S3 Key for the lambda deployment package zip file
AsgLogGroupRetentionInDays:
Type: Number
Description: >-
The number of days to retain the log events in the specified log group.
Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, and 3653.
Default: 3
AllowedValues: [ 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653]
GwlbAcceptanceRequiredVpcEps:
Type: String
Description: "Select \"true\" to require acceptance for new VPC Endpoints, else \"false\" (default)"
Default: false
AllowedValues:
- true
- false
GwlbCrossZoneLbEnabled:
Type: String
Description: "Select \"true\" to enable cross-zone load balancing (default), else \"false\""
Default: true
AllowedValues:
- true
- false
GwlbTargetGroupRebalanceOnDeregistrationOrUnhealthy:
Type: String
Description: "Select \"rebalance\" to enable rebalance failover on target deregistration or of target becomes unhealthy"
AllowedValues:
- no_rebalance
- rebalance
Default: rebalance
GwlbFlowStickiness:
Type: String
Description: >-
Select 2-tuple for source_ip_dest_ip, 3-tuple for source_ip_dest_ip_proto flow stickiness
Default: "5-tuple"
AllowedValues:
- "5-tuple"
- "2-tuple"
- "3-tuple"
GwlbVpcEpServicePrincipals:
Type: CommaDelimitedList
Default: ""
Description: "[Optional] A List of comma-separated service principal ARNs"
GwlbVpcEpSubnetIds:
Description: >-
[Optional] A List of comma-separated VPC EP Subnets to create VPC Endpoints in (one per Az).
Specifying subnets here will override Cloud-connector subnets being used for VPC Endpoints
Default: ""
Type: CommaDelimitedList
ZscalerAwsEc2InstanceType:
Type: String
Description: "The AWS EC2 instance type for the Cloud Connector instances"
Default: "m6i.large"
AllowedValues:
- t3.medium
- c5a.large
- m5n.large
- m6i.large
- c6i.large
- c6in.large
- m5n.4xlarge
- m6i.4xlarge
- c6i.4xlarge
- c6in.4xlarge
ZscalerCcInstanceProfile:
Description: "[Optional] Leave blank/empty to create a new IAM Role/Instance Profile"
Type: String
AllowedPattern: '^$|^arn:(aws|aws\\-cn|aws\\-us\\-gov):iam::[0-9]+:instance-profile/.*$'
ConstraintDescription: >-
Please specify a valid AWS IAM Role ARN
ZscalerCcInstanceSize:
AllowedValues:
- "small"
Default: "small"
Description: "The instance size for Zscaler Cloud Connector (small)"
Type: String
ZscalerCcMgmtIntfSecurityGroup:
Description: "[Optional] Leave blank/empty to create a new security group"
Type: String
AllowedPattern: "^$|^sg-[0-9a-f]+$"
ConstraintDescription: >-
Please enter a valid AWS:EC2::SecurityGroup::Id
ZscalerCcSrvcIntfSecurityGroup:
Description: "[Optional] Leave blank/empty to create a new security group"
Type: String
AllowedPattern: "^$|^sg-[0-9a-f]+$"
ConstraintDescription: >-
Please enter a valid AWS:EC2::SecurityGroup::Id
ZscalerCloudConnectorProvUrl:
AllowedPattern: '(admin|connector).zs.*.net(/ec)?/w?api/v1/provUrl\?name=[\w-_]+'
ConstraintDescription: >-
Please input the Cloud Connector Provisioning Template URL to use from
your Zscaler Cloud Connector Portal
Description: "Obtained from Cloud Connector Portal. Template requires Auto Scaling ENABLED in Group Information"
Type: String
ZscalerHttpProbePort:
Type: String
AllowedPattern: '^(80|102[4-9]|10[3-9]\d|1[1-9]\d{2}|[2-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$'
ConstraintDescription: >-
The HTTP probe port's allowed values are [80, 1024-65535]
Description: "HTTP Monitor probe port for Cloud Connector listen on for monitoring health probes. Allowed values are 80, 1024-65535. Defaults to 50000"
Default: 50000
ZscalerKeyPairName:
Type: AWS::EC2::KeyPair::KeyName
Description: "AWS EC2 Instance Access KeyPair"
ZscalerSecretManagerSecretName:
Type: String
Default: "ZS/CC/credentials"
Description: "Secret Manager Secret Name, defaults to ZS/CC/credentials"
ZscalerOsAmi:
Type: String
Description: "[Optional] Amazon EC2 Image ID to use for the deployment. Leave empty to deploy the latest marketplace AMI"
AllowedPattern: '^(ami-[0-9a-f]{17})?$'
ZscalerEBSEncryptionEnabled:
Type: String
Description: "Select \"true\" to enable EBS encryption (default), else \"false\""
Default: true
AllowedValues:
- true
- false
ZscalerCloudTagsEnabled:
Type: String
Description: "Select \"true\" to enable Cloud Tag Collection IAM Policy (default), else \"false\""
Default: true
AllowedValues:
- true
- false
ZscalerSupportServerRuleEnabled:
Type: String
Description: "Select \"true\" to enable creation of Management Security Group rule permitting egress TCP/12002 Zscaler Support Server Destinations (default), else \"false\" to not enable (Not recommended as this may prohibit Zscaler Support assistance if required)"
Default: true
AllowedValues:
- true
- false
Conditions:
ZscalerSecretsManagerNameNotEmpty: !Not
- !Equals
- !Ref ZscalerSecretManagerSecretName
- ""
ZscalerHttpProbePortNotEmpty: !Not
- !Equals
- !Ref ZscalerHttpProbePort
- ""
CreateMgmtIntfSecurityGroup: !Equals
- !Ref ZscalerCcMgmtIntfSecurityGroup
- ""
CreateSrvcIntfSecurityGroup: !Equals
- !Ref ZscalerCcSrvcIntfSecurityGroup
- ""
CreateIamAndInstanceProfile: !Equals
- !Ref ZscalerCcInstanceProfile
- ""
CreateAsgWarmPool: !Equals
- !Ref AsgWarmPoolEnabled
- true
UseRootAsServicePrincipal: !Equals
- !Join ["", !Ref GwlbVpcEpServicePrincipals]
- ""
EnableFlowStickiness: !Not
- !Equals
- !Ref GwlbFlowStickiness
- "5-tuple"
Use3TupleFlowStickiness: !Equals
- !Ref GwlbFlowStickiness
- "3-tuple"
CreateCloudTagsIAM: !Equals
- !Ref ZscalerCloudTagsEnabled
- true
CreateZsSupportRule: !And
- !Equals [!Ref ZscalerSupportServerRuleEnabled, true]
- !Condition CreateMgmtIntfSecurityGroup
Rules:
smallCCInstanceSize:
RuleCondition: !Equals
- !Ref ZscalerCcInstanceSize
- small
Assertions:
- Assert:
'Fn::Contains':
- - t3.medium
- t3a.medium
- c5a.large
- m5n.large
- m6i.large
- c6i.large
- c6in.large
- m5n.4xlarge
- m6i.4xlarge
- c6i.4xlarge
- c6in.4xlarge
- !Ref ZscalerAwsEc2InstanceType
AssertDescription: >-
For small ZscalerCcInstanceSize, the Instance type must be one of t3.medium, c5a.large, m5n.large, m6i.large, c6i.large, c6in.large, m5n.4xlarge, m6i.4xlarge, c6i.4xlarge
CCProvUrlNotEmpty:
Assertions:
- Assert: !Not
- !Equals
- !Ref ZscalerCloudConnectorProvUrl
- ''
AssertionDescription: Cloud Connector Provisioning URL cannot be empty!
Mappings:
PartitionExclusiveMap:
aws:
Runtime: python3.12
aws-us-gov:
Runtime: python3.11
aws-cn:
Runtime: python3.11
Product2Code:
CloudConnector:
Code: 2l8tfysndbav4tv2nfjwak3cu
Resources:
MgmtSecurityGroup:
Condition: CreateMgmtIntfSecurityGroup
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref NetworkVpcId
GroupDescription: Security group for Cloud Connector management interface
MgmtEgressRuleTcp443:
Condition: CreateMgmtIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC outbound TCP/443"
GroupId: !Ref MgmtSecurityGroup
IpProtocol: "tcp"
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
MgmtEgressRuleUdp123:
Condition: CreateMgmtIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC Mgmt outbound UDP/123"
GroupId: !Ref MgmtSecurityGroup
IpProtocol: "udp"
FromPort: 123
ToPort: 123
CidrIp: 0.0.0.0/0
MgmtEgressRuleTcp12002:
Condition: CreateZsSupportRule
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Recommended: CC Mgmt outbound Zscaler Remote Support TCP/12002"
GroupId: !Ref MgmtSecurityGroup
IpProtocol: "tcp"
FromPort: 12002
ToPort: 12002
CidrIp: 199.168.148.101/32
MgmtIngressRuleTcp22:
Condition: CreateMgmtIntfSecurityGroup
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: "Recommended: SSH to CC management"
GroupId: !Ref MgmtSecurityGroup
IpProtocol: "tcp"
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
ServiceSecurityGroup:
Condition: CreateSrvcIntfSecurityGroup
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: !Ref NetworkVpcId
GroupDescription: Security group for Cloud Connector service interfaces
ServiceEgressRuleTcp443:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC outbound TCP 443"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "tcp"
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
ServiceEgressRuleUdp443:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC Service outbound UDP 443"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "udp"
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
ServiceEgressRuleUdp123:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC Service outbound NTP"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "udp"
FromPort: 123
ToPort: 123
CidrIp: 0.0.0.0/0
ServiceEgressRuleUdp6081:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Required: CC GENEVE encapsulation traffic to GWLB from CC Service"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "udp"
FromPort: 6081
ToPort: 6081
CidrIp: 0.0.0.0/0
ServiceEgressRuleAny:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupEgress
Properties:
Description: "Optional: CC outbound all ports and protocols"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "-1"
CidrIp: 0.0.0.0/0
ServiceIngressRuleTcpHealthProbe:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: "Required: CC Service TCP health probe"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "tcp"
FromPort: !If [ZscalerHttpProbePortNotEmpty, !Ref ZscalerHttpProbePort, '50000']
ToPort: !If [ZscalerHttpProbePortNotEmpty, !Ref ZscalerHttpProbePort, '50000']
CidrIp: 0.0.0.0/0
ServiceIngressRuleTcp443:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: "Required: CC inbound internal VPC cluster TCP 443 communication"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "tcp"
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
ServiceIngressRuleUdp6081:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: "Required: CC GENEVE encapsulation traffic to CC Service from GWLB"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "udp"
FromPort: 6081
ToPort: 6081
CidrIp: 0.0.0.0/0
ServiceIngressRuleAny:
Condition: CreateSrvcIntfSecurityGroup
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: "Optional: Permit All Intra-VPC Traffic / Ensure CC Service Interfaces are able to communicate with each other freely"
GroupId: !Ref ServiceSecurityGroup
IpProtocol: "-1"
CidrIp: 0.0.0.0/0
CcGetSecretsPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: CreateIamAndInstanceProfile
Properties:
Description: Zscaler Cloud Connector Get Secrets Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'secretsmanager:GetSecretValue'
CcSsmControlPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: CreateIamAndInstanceProfile
Properties:
Description: Zscaler Cloud Connector Ssm Control Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'ssm:UpdateInstanceInformation'
- 'ssmmessages:CreateControlChannel'
- 'ssmmessages:CreateDataChannel'
- 'ssmmessages:OpenControlChannel'
- 'ssmmessages:OpenDataChannel'
Resource:
- '*'
CcCloudwatchMetricsPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: CreateIamAndInstanceProfile
Properties:
Description: Zscaler Cloud Connector Cloudwatch Metrics Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'cloudwatch:GetMetricStatistics'
- 'cloudwatch:ListMetrics'
- 'cloudwatch:PutMetricData'
- 'ec2:DescribeTags'
Resource:
- '*'
CcAutoScalingLifecycleActionsPolicy:
Type: AWS::IAM::ManagedPolicy
Condition: CreateIamAndInstanceProfile
Properties:
Description: Zscaler Cloud Connector Cloudwatch Metrics Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'autoscaling:DescribeLifecycleHookTypes'
- 'autoscaling:DescribeLifecycleHooks'
- 'autoscaling:DescribeAutoScalingInstances'
- 'autoscaling:CompleteLifecycleAction'
- 'autoscaling:RecordLifecycleActionHeartbeat'
- 'autoscaling:SetInstanceHealth'
- 'ec2:DescribeInstanceStatus'
Resource:
- '*'
CcCloudTagsPolicy:
Condition: CreateCloudTagsIAM
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Zscaler Cloud Connector AWS Workload Tagging Policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'sqs:DeleteMessage'
- 'sqs:ReceiveMessage'
- 'sqs:GetQueueUrl'
- 'sqs:GetQueueAttributes'
- 'sqs:SetQueueAttributes'
- 'sqs:DeleteQueue'
- 'sqs:CreateQueue'
- 'sns:Subscribe'
- 'sns:ListSubscriptions'
- 'sns:Unsubscribe'
Resource:
- '*'
CcIamRole:
Condition: CreateIamAndInstanceProfile
Type: 'AWS::IAM::Role'
Properties:
Description: Zscaler Cloud Connector Instance IAM Role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- !Ref CcGetSecretsPolicy
- !Ref CcSsmControlPolicy
- !Ref CcCloudwatchMetricsPolicy
- !Ref CcAutoScalingLifecycleActionsPolicy
- !If [CreateCloudTagsIAM, !Ref CcCloudTagsPolicy, !Ref AWS::NoValue]
CcInstanceProfile:
Condition: CreateIamAndInstanceProfile
Type: 'AWS::IAM::InstanceProfile'
Properties:
Roles:
- !Ref CcIamRole
CcLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: !Sub '${AWS::StackName}-CloudConnectorLaunchTemplate'
LaunchTemplateData:
InstanceType: !Ref ZscalerAwsEc2InstanceType
MetadataOptions:
HttpEndpoint: enabled
HttpTokens: required
InstanceMetadataTags: enabled
KeyName: !Ref ZscalerKeyPairName
UserData: !Base64
Fn::Join:
- |+
- - '[ZSCALER]'
- !Join
- '='
- - 'CC_URL'
- !Ref ZscalerCloudConnectorProvUrl
- !Join
- '='
- - 'SECRET_NAME'
- !If [ZscalerSecretsManagerNameNotEmpty, !Ref ZscalerSecretManagerSecretName, 'ZS/CC/credentials']
- !Join
- '='
- - 'HTTP_PROBE_PORT'
- !If [ZscalerHttpProbePortNotEmpty, !Ref ZscalerHttpProbePort, '50000']
TagSpecifications:
- ResourceType: instance
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-CloudConnector'
IamInstanceProfile: !If
- CreateIamAndInstanceProfile
- Arn: !GetAtt [ CcInstanceProfile, Arn ]
- Arn: !Ref ZscalerCcInstanceProfile
NetworkInterfaces:
- Description: Interface for service traffic
DeviceIndex: 0
Groups:
- "Fn::If": [CreateSrvcIntfSecurityGroup, !Ref ServiceSecurityGroup, !Ref ZscalerCcSrvcIntfSecurityGroup]
AssociatePublicIpAddress: false
- Description: Interface for mgmt traffic
DeviceIndex: 1
Groups:
- "Fn::If": [CreateMgmtIntfSecurityGroup, !Ref MgmtSecurityGroup, !Ref ZscalerCcMgmtIntfSecurityGroup]
AssociatePublicIpAddress: false
EbsOptimized: "true"
BlockDeviceMappings:
- Ebs:
VolumeType: gp3
DeleteOnTermination: true
Encrypted: !Ref ZscalerEBSEncryptionEnabled
DeviceName: /dev/sda1
CcAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: !Sub '${AWS::StackName}-CloudConnectorAutoScalingGroup'
HealthCheckGracePeriod: 900
HealthCheckType: EC2
DefaultInstanceWarmup: 0
LaunchTemplate:
LaunchTemplateId: !Ref CcLaunchTemplate
Version: !GetAtt CcLaunchTemplate.LatestVersionNumber
MaxSize: !Ref AsgMaxSize
MinSize: !Ref AsgMinSize
TargetGroupARNs:
- !Ref CcGwlbTargetGroup
VPCZoneIdentifier: !Ref NetworkCcSubnetIds
LifecycleHookSpecificationList:
- DefaultResult: "ABANDON"
HeartbeatTimeout: 1800
LifecycleHookName: !Sub '${AWS::StackName}-CcAutoScalingGroupInitialLifecycleHookForLaunch'
LifecycleTransition: "autoscaling:EC2_INSTANCE_LAUNCHING"
- DefaultResult: "CONTINUE"
HeartbeatTimeout: 900
LifecycleHookName: !Sub '${AWS::StackName}-CcAutoScalingGroupInitialLifecycleHookForTerminate'
LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"
MetricsCollection:
- Granularity: "1Minute"
CcAsgAutoScalingPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AutoScalingGroupName: !Ref CcAutoScalingGroup
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
# PredefinedMetricSpecification:
# PredefinedMetricType: !Ref AsgTargetTrackingMetric
CustomizedMetricSpecification:
MetricName: 'smedge_cpu_utilization'
Namespace: 'Zscaler/CloudConnectors'
Dimensions:
- Name: AutoScalingGroupName
Value: !Ref CcAutoScalingGroup
Statistic: Average
Unit: Percent
TargetValue: !Ref AsgTargetCpuUtilValue
CcAsgWarmPool:
Condition: CreateAsgWarmPool
Type: AWS::AutoScaling::WarmPool
Properties:
AutoScalingGroupName: !Ref CcAutoScalingGroup
InstanceReusePolicy:
ReuseOnScaleIn: !Ref AsgWarmPoolReuseOnScaleIn
MinSize: !Ref AsgWarmPoolMinSize
MaxGroupPreparedCapacity: !Ref AsgWarmPoolMaxGroupPreparedCapacity
PoolState: !Ref AsgWarmPoolState
# ASG Lambda Related resources
CcCloudwatchLogGroupForLambda:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub '${AWS::StackName}-CcCloudwatchLogGroupForLambda'
RetentionInDays: !Ref AsgLogGroupRetentionInDays
CcGetSecretsPolicyForLambda:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Zscaler Cloud Connector Get Secrets Policy For Lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'secretsmanager:GetSecretValue'
CcCloudwatchMetricsPolicyForLambda:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Zscaler Cloud Connector Cloudwatch Metrics Policy For Lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'cloudwatch:GetMetricStatistics'
- 'cloudwatch:ListMetrics'
- 'cloudwatch:GetMetricData'
- 'ec2:DescribeTags'
Resource:
- '*'
CcCloudwatchLogsPolicyForLambda:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Zscaler Cloud Connector Cloudwatch Logs Policy For Lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource:
- !GetAtt
- CcCloudwatchLogGroupForLambda
- Arn
CcAutoScalingLifecycleActionsPolicyForLambda:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Zscaler Cloud Connector Cloudwatch Metrics Policy For Lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'autoscaling:DescribeLifecycleHookTypes'
- 'autoscaling:DescribeLifecycleHooks'
- 'autoscaling:DescribeAutoScalingInstances'
- 'autoscaling:CompleteLifecycleAction'
- 'autoscaling:RecordLifecycleActionHeartbeat'
- 'autoscaling:SetInstanceHealth'
- 'autoscaling:DescribeAutoScalingGroups'
- 'autoscaling:DescribeWarmPool'
- 'ec2:DescribeInstanceStatus'
- 'ec2:DescribeInstances'
- 'ec2:DescribeTags'
Resource:
- '*'
CcAsgLambdaRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- !Ref CcGetSecretsPolicyForLambda
- !Ref CcCloudwatchMetricsPolicyForLambda
- !Ref CcAutoScalingLifecycleActionsPolicyForLambda
- !Ref CcCloudwatchLogsPolicyForLambda
CcAsgLambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Handler: zscaler_cc_lambda_service.lambda_handler
Description: Auto Scaling Group Lambda for Failure management
Timeout: 180 # executes for max 180 seconds
MemorySize: 256
Architectures: ['arm64']
Role: !GetAtt
- CcAsgLambdaRole
- Arn
Runtime: !FindInMap [PartitionExclusiveMap, !Ref "AWS::Partition", Runtime] # set lambda runtime to python3.11 in partition is aws-cn or aws-us-gov
Environment:
Variables:
ASG_NAMES: !Sub '{json_dump_asg_names}'
CC_URL: !Ref ZscalerCloudConnectorProvUrl
SECRET_NAME: !If [ZscalerSecretsManagerNameNotEmpty, !Ref ZscalerSecretManagerSecretName, 'ZS/CC/credentials']
HC_DATA_POINTS: '10' # most recent datapoints to evaluate
HC_UNHEALTHY_THRESHOLD: '7' # unhealthy datapoints threshold
HC_UNHEALTHY_CONTIGUOUS_DP: '5' # continuous unhealthy datapoint counts
MISSING_DATAPOINTS_UNHEALTHY: true # treat missing datapoints as unhealthy
Code:
S3Bucket: !Ref AsgS3BucketName
S3Key: !Ref AsgS3Key
LoggingConfig:
LogFormat: 'Text'
LogGroup: !Ref CcCloudwatchLogGroupForLambda
## Event-bridge Terminate rule and Lambda permission
CcAsgEventBridgeInstanceTerminateLifecycleActionRule:
Type: AWS::Events::Rule
Properties:
Description: 'Event rule for EC2 Instance-terminate Lifecycle Action'
EventPattern: !Sub |
{
"source": ["aws.autoscaling"],
"detail-type": ["EC2 Instance-terminate Lifecycle Action"],
"detail": {
"AutoScalingGroupName": "{json_dump_asg_names}"
}
}
State: "ENABLED"
Targets:
- Arn:
Fn::GetAtt:
- CcAsgLambdaFunction
- Arn
Id: !Ref CcAsgLambdaFunction
CcAsgEventBridgeInstanceTerminateLifecycleActionRuleToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: CcAsgLambdaFunction
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- CcAsgEventBridgeInstanceTerminateLifecycleActionRule
- Arn
## Event-bridge Terminate rule and Targets for EC2 Terminations
CcAsgEventBridgeEc2InstanceTerminateRule:
Type: AWS::Events::Rule
Properties:
Description: 'Event rule for EC2 Instance-termination without Lifecycle Action'
EventPattern: |
{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["terminated"]