forked from runs-on/runs-on
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
2431 lines (2282 loc) · 83.3 KB
/
template.yaml
File metadata and controls
2431 lines (2282 loc) · 83.3 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
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: CloudFormation stack for https://runs-on.com
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "App configuration [required]"
Parameters:
- GithubOrganization
- GithubEnterpriseUrl
- LicenseKey
- EmailAddress
- Label:
default: "VPC configuration [optional]"
Parameters:
- VpcCidrBlock
- VpcCidrSubnetBits
- VpcEndpoints
- Private
- NatGatewayAvailability
- NatGatewayElasticIPCount
- Ipv6Enabled
- VpcFlowLogFormat
- VpcFlowLogS3BucketArn
- VpcFlowLogRetentionInDays
- Label:
default: "Security settings [optional]"
Parameters:
- SSHAllowed
- SSHCidrRange
- EC2InstanceCustomPolicy
- DefaultPermissionBoundaryArn
- ServerPassword
- DefaultAdmins
- EncryptEbs
- Label:
default: "Alert and monitoring settings [optional]"
Parameters:
- AppAlarmDailyMinutes
- CostReportsEnabled
- AlertTopicSubscriptionHttpsEndpoint
- ECInstanceDetailedMonitoring
- Ec2LogRetentionInDays
- SqsQueueOldestMessageThresholdSeconds
- Label:
default: "Integrations [optional]"
Parameters:
- IntegrationStepSecurityApiKey
- Label:
default: "Advanced app configuration [optional]"
Parameters:
- Environment
- RunnerCustomTags
- RunnerDefaultDiskSize
- RunnerDefaultDiskDeviceName
- RunnerDefaultVolumeThroughput
- RunnerLargeDiskSize
- RunnerLargeDiskDeviceName
- RunnerLargeVolumeThroughput
- AppEc2QueueSize
- AppCPU
- AppMemory
- AppRegistry
- SpotCircuitBreaker
- S3CacheExpirationInDays
- CostAllocationTag
Parameters:
GithubOrganization:
Type: String
Description: "For instance if your GitHub organization lives at github.com/my-org, then the value of this parameter should be: my-org"
MinLength: 1
GithubEnterpriseUrl:
Type: String
Default: ""
Description: "Leave blank, unless you use a self-hosted GitHub Enterprise Server (GHES) instance. In that case, if your GHES instance lives at https://github.mycompany.com, then the value of this parameter should be: https://github.mycompany.com"
LicenseKey:
Type: String
Description: |
License key for RunsOn, either as a string or SSM parameter ARN (with the format `arn:aws:ssm:REGION:ACCOUNT:parameter/STACK_NAME/license-key`). Get one at https://runs-on.com/pricing.
MinLength: 1
EmailAddress:
Type: String
Description: Email address for cost and alert reports. You will receive a confirmation email from AWS at this address during the installation so make sure to use a valid address. You must confirm it if you want to receive cost and alert reports.
MinLength: 1
Environment:
Type: String
Default: "production"
MinLength: 1
Description: "Make RunsOn only listen to jobs with an `env` job label matching this value. Only change this if you know what you are doing. See https://runs-on.com/configuration/environments/ for more details."
AlertTopicSubscriptionHttpsEndpoint:
Type: String
Description: HTTPS endpoint for cost and alert reports.
Default: ""
VpcCidrBlock:
Type: String
Description: CIDR block for the VPC. Updating this value after creation will require deleting the stack and recreating it.
Default: 10.1.0.0/16
VpcCidrSubnetBits:
Type: Number
Description: Number of bits to allocate for the subnet. For example, if you specify VpcCidrBlock to a /16 (the default), and this value to 12 (the default), you will have 4 bits, i.e. max 16 subnets in the VPC. Updating this value after creation will require deleting the stack and recreating it.
Default: 12
MinValue: 9
MaxValue: 16
Ipv6Enabled:
Type: String
Default: "false"
AllowedValues:
- "true"
- "false"
Description: Enable or disable IPv6 for runners. Disabling ipv6 might help with Docker Hub rate limiting issues.
SSHAllowed:
Type: String
Default: "true"
AllowedValues:
- "true"
- "false"
Description: Allow inbound SSH connections from the specified CIDR range to the runners.
SSHCidrRange:
Type: String
Default: 0.0.0.0/0
Description: CIDR range for inbound SSH access. By default, only repository collaborators with admin permission will be able to SSH into the runner instances.
MinLength: 1
Private:
Type: String
Default: "false"
AllowedValues:
- "only"
- "always"
- "true"
- "false"
Description: "Enable ('true', 'always', 'only') or disable ('false') private networking. If 'true', your jobs can opt-in to launch in private subnets with the `private=true` label, and they will get a static egress IP. If 'always', all jobs will run in private subnets, and they will all get a static egress IP, unless you manually opt-out in your job definition with the `private=false` label. If 'only', then jobs can only launch in private subnets. Note that enabling it will create 1 managed NAT gateway, with the corresponding costs. More details at https://runs-on.com/networking/static-ips/."
VpcEndpoints:
Type: String
Default: "none"
AllowedValues:
- "EC2"
- "ECR"
- "EC2+ECR"
- "none"
Description: "Enable or disable VPC endpoints among: EC2 (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/interface-vpc-endpoints.html), ECR (API + Docker - https://docs.aws.amazon.com/AmazonECR/latest/userguide/vpc-endpoints.html). Each endpoint incurs ~$21.6/month ($7.2/month per AZ x3)."
NatGatewayElasticIPCount:
Type: Number
Default: 1
MinValue: 1
MaxValue: 8
Description: "Number of Elastic IPv4s to attach to _each_ NAT Gateway. Only applies if Private mode is enabled. Defaults to 1. Maximum of 8. Increasing this number is useful if you launch a large number of runners and are rate-limited by some external services due to the limited number of NAT Gateway IP addresses. Incurs ~$3.6/month additional cost for each Elastic IP. Note that by default you are limited to 2 EIPs per NAT gateway, but can request a quota increase from AWS."
NatGatewayAvailability:
Type: String
Default: SingleAZ
AllowedValues:
- SingleAZ
- MultiAZ
Description: "Create either a single NAT Gateway (SingleAZ) for all 3 availability zones, or a NAT Gateway per Availability Zone (MultiAZ). Only applies if Private mode is enabled. Each gateway incurs ~$32.4/month, plus bandwidth costs."
VpcFlowLogFormat:
Type: String
Default: ""
Description: "VPC Flow Log format. If blank, no VPC Flow Logs will be created. If set to `default`, the default format will be used. More details at https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html#flow-logs-fields"
VpcFlowLogS3BucketArn:
Type: String
Default: ""
Description: "ARN of an S3 bucket to send VPC Flow Logs to in addition to the default CloudWatch logs group. If blank, the logs will only be sent to CloudWatch Logs."
VpcFlowLogRetentionInDays:
Type: Number
Default: 7
MinValue: 1
Description: "Retention period in days for VPC Flow Logs."
DefaultPermissionBoundaryArn:
Type: String
Default: ""
Description: "ARN of an IAM policy that will be assigned as permission boundary to roles created by the stack. If blank, the roles will not have a permission boundary."
DefaultAdmins:
Type: String
Default: ""
Description: Comma-separated list of GitHub usernames that will always be granted SSH access to all the runner instances (if SSH access is enabled), in addition to any repository admins. If blank, only repository collaborators with admin permission will be able to SSH into the runner instances.
AppEc2QueueSize:
Type: Number
Default: 2
MinValue: 1
Description: "Number of queued jobs that can be processed concurrently by RunsOn. Each job takes about 2-3s to process. Increasing this value should be done with caution, as it will increase the number of EC2 instances that will be launched at once, eating into your AWS and GitHub rate limits. New AWS accounts come with a rate-limit of 2 RunInstances call/s, although you can request a higher limit from AWS (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/throttling.html)."
AppAlarmDailyMinutes:
Type: Number
Default: "4000"
Description: "Trigger an alarm if the cumulative number of minutes consumed during a day is over that number."
AppCPU:
Type: Number
AllowedValues:
- 256
- 512
- 1024
- 2048
- 4096
Default: 256
Description: CPU units for RunsOn service (256 or higher). You might only need to change this if you have 10k+ jobs per day.
AppMemory:
Type: Number
AllowedValues:
- 512
- 1024
- 2048
- 3072
- 4096
- 6144
- 8192
Default: 512
Description: Memory in MB for RunsOn service (512 or higher). You might only need to change this if you have 10k+ jobs per day.
AppRegistry:
Type: String
Default: "public.ecr.aws/c5h5o9k1/runs-on/runs-on"
Description: "Docker image (public) registry for the RunsOn service."
SpotCircuitBreaker:
Type: String
Default: "2/15/30"
AllowedPattern: "^(false|[0-9]+/[0-9]+/[0-9]+)$"
Description: "Enable (`COUNT/WINDOW_MINUTES/RECOVERY_MINUTES`) or disable (`false`) the spot instance circuit breaker. If enabled, the circuit breaker will prevent the stack from launching new spot instances during RECOVERY_MINUTES if there was at least COUNT spot interruptions during the last WINDOW_MINUTES. For instance 2/15/30 will prevent the stack from launching new spot instances during 30 minutes if there was at least 2 spot interruptions during the last 15 minutes."
EncryptEbs:
Type: String
Default: "false"
AllowedValues:
- "true"
- "false"
Description: "Encrypt the EBS volumes of the runner instances. Encryption will slow the boot time of runner instances by ~10s."
RunnerDefaultDiskSize:
Type: Number
Default: 40
MinValue: 40
Description: Disk size in GB for `disk=default` runners.
RunnerDefaultDiskDeviceName:
Type: String
Default: "/dev/sda1"
Description: Name of the root volume device name for the `disk=default` runner. Only change this if you plan on using custom AMIs that have a different root volume name.
RunnerDefaultVolumeThroughput:
Type: Number
Default: 400
MinValue: 125
MaxValue: 1000
Description: Volume throughput in MiB/s for `disk=default` runners (helps with faster boot times, but costs more).
RunnerLargeDiskSize:
Type: Number
Default: 80
MinValue: 40
Description: Disk size in GB for `disk=large` runners.
RunnerLargeDiskDeviceName:
Type: String
Default: "/dev/sda1"
Description: Name of the root volume device name for the `disk=large` runner. Only change this if you plan on using custom AMIs that have a different root volume name.
RunnerLargeVolumeThroughput:
Type: Number
Default: 750
MinValue: 125
MaxValue: 1000
Description: Volume throughput in MiB/s for `disk=large` runners (helps with faster boot times, but costs more).
RunnerCustomTags:
Type: CommaDelimitedList
Default: ""
Description: "Optional custom tags for the runner instances (e.g. 'key1=value1,key2=value2'). Tag keys cannot start with `runs-on`, and can only use letters (a-z, A-Z), numbers (0-9), and the following characters: + - = . , _ : @ (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions)"
CostReportsEnabled:
Type: String
Default: "true"
AllowedValues:
- "true"
- "false"
Description: Enable or disable cost reports sent by email.
EC2InstanceCustomPolicy:
Type: String
Default: ""
Description: "Optional managed IAM Policy ARN to assign to the EC2 runner instances."
ECInstanceDetailedMonitoring:
Type: String
Default: "false"
AllowedValues:
- "true"
- "false"
Description: Enable or disable detailed monitoring for EC2 instances (can incur additional costs).
Ec2LogRetentionInDays:
Type: Number
Default: 7
MinValue: 1
Description: "Retention period in days for EC2 instance logs."
SqsQueueOldestMessageThresholdSeconds:
Type: Number
Default: 0
Description: Trigger an alarm per sqs queue if the oldest message in that queue is older than this time in seconds. Leave as 0 to disable SQS alarms.
ServerPassword:
Type: String
Default: ""
Description: Password for the /metrics Prometheus endpoint (https://runs-on.com/monitoring/metrics/#prometheus-metrics). If blank, the endpoint will be disabled.
S3CacheExpirationInDays:
Type: Number
Default: 10
Description: "Number of days to keep cache entries in the S3 cache bucket."
CostAllocationTag:
Type: String
Default: "stack"
Description: "Cost allocation tag to use for all the deployed resources. Updating this after creation will require deleting the stack and recreating it."
IntegrationStepSecurityApiKey:
Type: String
Default: ""
Description: "API key for Step Security (https://stepsecurity.io/)."
Mappings:
App:
Image:
Tag: "v2.7.2"
Conditions:
EmailProvided: !Not [!Equals [!Ref EmailAddress, ""]]
CostReportsEnabled: !Equals [!Ref CostReportsEnabled, "true"]
AlertTopicSubscriptionHttpsProvided:
!Not [!Equals [!Ref AlertTopicSubscriptionHttpsEndpoint, ""]]
HasPrivateSubnet: !Not [!Equals [!Ref Private, "false"]]
PrivateSubnetIsMultiAZ: !And [!Condition HasPrivateSubnet, !Equals [!Ref NatGatewayAvailability, "MultiAZ"]]
HasEncryptEbs: !Equals [!Ref EncryptEbs, "true"]
IsPrivateOnly: !Equals [!Ref Private, "only"]
CustomPolicyProvided: !Not [!Equals [!Ref EC2InstanceCustomPolicy, ""]]
ECInstanceDetailedMonitoringEnabled: !Equals ["true", !Ref ECInstanceDetailedMonitoring]
CreateElasticIP1: !And [!Condition HasPrivateSubnet, !Not [!Equals [!Ref NatGatewayElasticIPCount, 0]]]
CreateElasticIP2: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP1, !Not [!Equals [!Ref NatGatewayElasticIPCount, 1]]]
CreateElasticIP3: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP2, !Not [!Equals [!Ref NatGatewayElasticIPCount, 2]]]
CreateElasticIP4: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP3, !Not [!Equals [!Ref NatGatewayElasticIPCount, 3]]]
CreateElasticIP5: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP4, !Not [!Equals [!Ref NatGatewayElasticIPCount, 4]]]
CreateElasticIP6: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP5, !Not [!Equals [!Ref NatGatewayElasticIPCount, 5]]]
CreateElasticIP7: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP6, !Not [!Equals [!Ref NatGatewayElasticIPCount, 6]]]
CreateElasticIP8: !And [!Condition HasPrivateSubnet, !Condition CreateElasticIP7, !Not [!Equals [!Ref NatGatewayElasticIPCount, 7]]]
CreateElasticIP1B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP1]
CreateElasticIP2B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP2]
CreateElasticIP3B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP3]
CreateElasticIP4B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP4]
CreateElasticIP5B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP5]
CreateElasticIP6B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP6]
CreateElasticIP7B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP7]
CreateElasticIP8B: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP8]
CreateElasticIP1C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP1]
CreateElasticIP2C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP2]
CreateElasticIP3C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP3]
CreateElasticIP4C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP4]
CreateElasticIP5C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP5]
CreateElasticIP6C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP6]
CreateElasticIP7C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP7]
CreateElasticIP8C: !And [!Condition PrivateSubnetIsMultiAZ, !Condition CreateElasticIP8]
CreateInterfaceEndpointEc2: !Or [!Equals [!Ref VpcEndpoints, "EC2"], !Equals [!Ref VpcEndpoints, "EC2+ECR"]]
CreateInterfaceEndpointEcrApi: !Or [!Equals [!Ref VpcEndpoints, "ECR"], !Equals [!Ref VpcEndpoints, "EC2+ECR"]]
CreateInterfaceEndpointEcrDocker: !Or [!Equals [!Ref VpcEndpoints, "ECR"], !Equals [!Ref VpcEndpoints, "EC2+ECR"]]
CreateSqsQueueOldestMessageAlarms: !Not [!Equals [!Ref SqsQueueOldestMessageThresholdSeconds, 0]]
HasDefaultPermissionBoundaryArn: !Not [!Equals [!Ref DefaultPermissionBoundaryArn, ""]]
HasVpcFlowLogEnabled: !Not [!Equals [!Ref VpcFlowLogFormat, ""]]
HasVpcFlowLogFormat: !Not [!Equals [!Ref VpcFlowLogFormat, "default"]]
HasVpcFlowLogS3BucketArn: !And [!Condition HasVpcFlowLogEnabled, !Not [!Equals [!Ref VpcFlowLogS3BucketArn, ""]]]
HasIpv6Enabled: !Equals [!Ref Ipv6Enabled, "true"]
HasSSHAllowed: !Equals [!Ref SSHAllowed, "true"]
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCidrBlock
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-VPC
VPCIPv6CidrBlock:
Type: AWS::EC2::VPCCidrBlock
Properties:
VpcId: !Ref VPC
AmazonProvidedIpv6CidrBlock: true
# EC2.6 - VPC flow logging should be enabled in all VPCs
VPCFlowLog:
Type: AWS::EC2::FlowLog
Condition: HasVpcFlowLogEnabled
Properties:
ResourceType: VPC
ResourceId: !Ref VPC
TrafficType: ALL
DeliverLogsPermissionArn: !GetAtt VPCFlowLogRole.Arn
LogDestinationType: cloud-watch-logs
LogGroupName: !Ref VPCFlowLogGroup
LogFormat: !If [HasVpcFlowLogFormat, !Ref VpcFlowLogFormat, !Ref "AWS::NoValue"]
VPCFlowLogGroup:
Type: AWS::Logs::LogGroup
Condition: HasVpcFlowLogEnabled
Properties:
RetentionInDays: !Ref VpcFlowLogRetentionInDays
VPCFlowLogS3:
Condition: HasVpcFlowLogS3BucketArn
Type: AWS::EC2::FlowLog
Properties:
ResourceType: VPC
ResourceId: !Ref VPC
TrafficType: ALL
LogDestinationType: s3
LogDestination: !Ref VpcFlowLogS3BucketArn
LogFormat: !If [HasVpcFlowLogFormat, !Ref VpcFlowLogFormat, !Ref "AWS::NoValue"]
VPCFlowLogRole:
Type: AWS::IAM::Role
Condition: HasVpcFlowLogEnabled
Properties:
PermissionsBoundary: !If [HasDefaultPermissionBoundaryArn, !Ref DefaultPermissionBoundaryArn, !Ref "AWS::NoValue"]
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: vpc-flow-logs.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: allow-flow-logs
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogGroups
- logs:DescribeLogStreams
Resource: !GetAtt VPCFlowLogGroup.Arn
PrivateSubnet1RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet1RouteTable
PrivateSubnet2RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet2RouteTable
PrivateSubnet3RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet3RouteTable
PrivateSubnet1Route:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet1RouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref PrivateSubnetGateway1
PrivateSubnet1RouteIPv6:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet1RouteTable
DestinationIpv6CidrBlock: ::/0
EgressOnlyInternetGatewayId: !Ref EgressOnlyInternetGateway
PrivateSubnet2Route:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet2RouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !If [PrivateSubnetIsMultiAZ, !Ref PrivateSubnetGateway2, !Ref PrivateSubnetGateway1]
PrivateSubnet2RouteIPv6:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet2RouteTable
DestinationIpv6CidrBlock: ::/0
EgressOnlyInternetGatewayId: !Ref EgressOnlyInternetGateway
PrivateSubnet3Route:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet3RouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !If [PrivateSubnetIsMultiAZ, !Ref PrivateSubnetGateway3, !Ref PrivateSubnetGateway1]
PrivateSubnet3RouteIPv6:
Condition: HasPrivateSubnet
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateSubnet3RouteTable
DestinationIpv6CidrBlock: ::/0
EgressOnlyInternetGatewayId: !Ref EgressOnlyInternetGateway
EgressOnlyInternetGateway:
Type: AWS::EC2::EgressOnlyInternetGateway
Properties:
VpcId: !Ref VPC
PrivateSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet1
RouteTableId: !Ref PrivateSubnet1RouteTable
PrivateSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet2
RouteTableId: !Ref PrivateSubnet2RouteTable
PrivateSubnet3RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet3
RouteTableId: !Ref PrivateSubnet3RouteTable
PrivateSubnet1:
Type: AWS::EC2::Subnet
DependsOn: VPCIPv6CidrBlock
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [0, !GetAZs ""]
CidrBlock: !Select [8, !Cidr [!GetAtt [VPC, CidrBlock], 16, !Ref VpcCidrSubnetBits]]
MapPublicIpOnLaunch: false
AssignIpv6AddressOnCreation: true
Ipv6CidrBlock:
Fn::Select:
- 0
- Fn::Cidr:
- Fn::Select:
- 0
- Fn::GetAtt:
- VPC
- Ipv6CidrBlocks
- 256
- 64
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet1
PrivateSubnet2:
Type: AWS::EC2::Subnet
DependsOn: VPCIPv6CidrBlock
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [1, !GetAZs ""]
CidrBlock: !Select [9, !Cidr [!GetAtt [VPC, CidrBlock], 16, !Ref VpcCidrSubnetBits]]
MapPublicIpOnLaunch: false
AssignIpv6AddressOnCreation: true
Ipv6CidrBlock:
Fn::Select:
- 1
- Fn::Cidr:
- Fn::Select:
- 0
- Fn::GetAtt:
- VPC
- Ipv6CidrBlocks
- 256
- 64
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet2
PrivateSubnet3:
Type: AWS::EC2::Subnet
DependsOn: VPCIPv6CidrBlock
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [2, !GetAZs ""]
CidrBlock: !Select [10, !Cidr [!GetAtt [VPC, CidrBlock], 16, !Ref VpcCidrSubnetBits]]
MapPublicIpOnLaunch: false
AssignIpv6AddressOnCreation: true
Ipv6CidrBlock:
Fn::Select:
- 2
- Fn::Cidr:
- Fn::Select:
- 0
- Fn::GetAtt:
- VPC
- Ipv6CidrBlocks
- 256
- 64
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnet3
PrivateSubnetGateway1:
Condition: HasPrivateSubnet
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !If
- CreateElasticIP1
- !GetAtt ElasticIP1.AllocationId
- !Ref AWS::NoValue
SecondaryAllocationIds:
- !If [CreateElasticIP2, !GetAtt ElasticIP2.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP3, !GetAtt ElasticIP3.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP4, !GetAtt ElasticIP4.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP5, !GetAtt ElasticIP5.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP6, !GetAtt ElasticIP6.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP7, !GetAtt ElasticIP7.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP8, !GetAtt ElasticIP8.AllocationId, !Ref "AWS::NoValue"]
SubnetId: !Ref PublicSubnet1
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnetGateway1
PrivateSubnetGateway2:
Condition: PrivateSubnetIsMultiAZ
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !If
- CreateElasticIP1B
- !GetAtt ElasticIP1B.AllocationId
- !Ref AWS::NoValue
SecondaryAllocationIds:
- !If [CreateElasticIP2B, !GetAtt ElasticIP2B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP3B, !GetAtt ElasticIP3B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP4B, !GetAtt ElasticIP4B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP5B, !GetAtt ElasticIP5B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP6B, !GetAtt ElasticIP6B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP7B, !GetAtt ElasticIP7B.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP8B, !GetAtt ElasticIP8B.AllocationId, !Ref "AWS::NoValue"]
SubnetId: !Ref PublicSubnet2
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnetGateway2
PrivateSubnetGateway3:
Condition: PrivateSubnetIsMultiAZ
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !If
- CreateElasticIP1C
- !GetAtt ElasticIP1C.AllocationId
- !Ref AWS::NoValue
SecondaryAllocationIds:
- !If [CreateElasticIP2C, !GetAtt ElasticIP2C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP3C, !GetAtt ElasticIP3C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP4C, !GetAtt ElasticIP4C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP5C, !GetAtt ElasticIP5C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP6C, !GetAtt ElasticIP6C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP7C, !GetAtt ElasticIP7C.AllocationId, !Ref "AWS::NoValue"]
- !If [CreateElasticIP8C, !GetAtt ElasticIP8C.AllocationId, !Ref "AWS::NoValue"]
SubnetId: !Ref PublicSubnet3
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-PrivateSubnetGateway3
ElasticIP1:
Condition: CreateElasticIP1
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP1
ElasticIP2:
Condition: CreateElasticIP2
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP2
ElasticIP3:
Condition: CreateElasticIP3
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP3
ElasticIP4:
Condition: CreateElasticIP4
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP4
ElasticIP5:
Condition: CreateElasticIP5
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP5
ElasticIP6:
Condition: CreateElasticIP6
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP6
ElasticIP7:
Condition: CreateElasticIP7
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP7
ElasticIP8:
Condition: CreateElasticIP8
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP8
ElasticIP1B:
Condition: CreateElasticIP1B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP1B
ElasticIP2B:
Condition: CreateElasticIP2B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP2B
ElasticIP3B:
Condition: CreateElasticIP3B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP3B
ElasticIP4B:
Condition: CreateElasticIP4B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP4B
ElasticIP5B:
Condition: CreateElasticIP5B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP5B
ElasticIP6B:
Condition: CreateElasticIP6B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP6B
ElasticIP7B:
Condition: CreateElasticIP7B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP7B
ElasticIP8B:
Condition: CreateElasticIP8B
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP8B
ElasticIP1C:
Condition: CreateElasticIP1C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP1C
ElasticIP2C:
Condition: CreateElasticIP2C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP2C
ElasticIP3C:
Condition: CreateElasticIP3C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP3C
ElasticIP4C:
Condition: CreateElasticIP4C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP4C
ElasticIP5C:
Condition: CreateElasticIP5C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP5C
ElasticIP6C:
Condition: CreateElasticIP6C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP6C
ElasticIP7C:
Condition: CreateElasticIP7C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP7C
ElasticIP8C:
Condition: CreateElasticIP8C
Type: AWS::EC2::EIP
Properties:
Domain: vpc
Tags:
- Key: !Ref CostAllocationTag
Value: !Ref AWS::StackName
- Key: Name
Value: !Sub ${AWS::StackName}-ElasticIP8C
PublicSubnet1:
Type: AWS::EC2::Subnet
DependsOn: VPCIPv6CidrBlock
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [0, !GetAZs ""]
CidrBlock: !Select [0, !Cidr [!GetAtt [VPC, CidrBlock], 16, !Ref VpcCidrSubnetBits]]
MapPublicIpOnLaunch: !If [IsPrivateOnly, false, true]
AssignIpv6AddressOnCreation: true
Ipv6CidrBlock:
Fn::Select:
- 3
- Fn::Cidr:
- Fn::Select:
- 0
- Fn::GetAtt:
- VPC
- Ipv6CidrBlocks
- 256