forked from zconsulting-co/aws-moodle-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-publicalb.yaml
192 lines (180 loc) · 6.03 KB
/
03-publicalb.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
AWSTemplateFormatVersion: 2010-09-09
Description: Reference Architecture to host Moodle on AWS - Creates Application Load Balancer
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: ALB Parameters
Parameters:
- Vpc
- PublicAlbAcmCertificate
- PublicAlbSecurityGroup
- NumberOfSubnets
- Subnet
ParameterLabels:
Vpc:
default: Vpc Id
PublicAlbAcmCertificate:
default: ALB Certificate ARN
PublicAlbSecurityGroup:
default: Public ALB Security Group
NumberOfSubnets:
default: Number of subnets
Subnet:
default: Subnets
Parameters:
NumberOfSubnets:
AllowedValues:
- 2
- 3
- 4
- 5
- 6
Default: 3
Description: Number of subnets. This must match your selections in the list of subnets below.
Type: String
PublicAlbAcmCertificate:
AllowedPattern: ^$|(arn:aws:acm:)([a-z0-9/:-])*([a-z0-9])$
Description: '[ Optional ] The AWS Certification Manager certificate ARN for the ALB certificate - this certificate should be created in the region you wish to run the ALB and must reference the Moodle domain name you use below.'
Type: String
PublicAlbSecurityGroup:
Description: Select the ALB security group.
Type: AWS::EC2::SecurityGroup::Id
Subnet:
Description: Select existing subnets. The number selected must match the number of subnets above. Subnets selected must be in separate AZs.
Type: List<AWS::EC2::Subnet::Id>
Vpc:
Description: Select an existing Vpc
Type: AWS::EC2::VPC::Id
Conditions:
SslCertificate:
!Not [!Equals [ '', !Ref PublicAlbAcmCertificate ] ]
NoSslCertificate:
!Equals [ '', !Ref PublicAlbAcmCertificate ]
NumberOfSubnets1:
!Equals [ 1, !Ref NumberOfSubnets ]
NumberOfSubnets2:
!Equals [ 2, !Ref NumberOfSubnets ]
NumberOfSubnets3:
!Equals [ 3, !Ref NumberOfSubnets ]
NumberOfSubnets4:
!Equals [ 4, !Ref NumberOfSubnets ]
NumberOfSubnets5:
!Equals [ 5, !Ref NumberOfSubnets ]
NumberOfSubnets6:
!Equals [ 6, !Ref NumberOfSubnets ]
Subnet0: !Or
- !Condition NumberOfSubnets1
- !Condition NumberOfSubnets2
- !Condition NumberOfSubnets3
- !Condition NumberOfSubnets4
- !Condition NumberOfSubnets5
- !Condition NumberOfSubnets6
Subnet1: !Or
- !Condition NumberOfSubnets2
- !Condition NumberOfSubnets3
- !Condition NumberOfSubnets4
- !Condition NumberOfSubnets5
- !Condition NumberOfSubnets6
Subnet2: !Or
- !Condition NumberOfSubnets3
- !Condition NumberOfSubnets4
- !Condition NumberOfSubnets5
- !Condition NumberOfSubnets6
Subnet3: !Or
- !Condition NumberOfSubnets4
- !Condition NumberOfSubnets5
- !Condition NumberOfSubnets6
Subnet4: !Or
- !Condition NumberOfSubnets5
- !Condition NumberOfSubnets6
Subnet5: !Condition NumberOfSubnets6
Resources:
PublicAlbListenerNoSslCertificate:
Type : AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref PublicAlbTargetGroup
LoadBalancerArn: !Ref PublicApplicationLoadBalancer
Port: 80
Protocol: HTTP
PublicAlbListenerSslCertificate:
Condition: SslCertificate
Type : AWS::ElasticLoadBalancingV2::Listener
Properties:
Certificates:
- CertificateArn: !Ref PublicAlbAcmCertificate
DefaultActions:
- Type: forward
TargetGroupArn: !Ref PublicAlbTargetGroup
LoadBalancerArn: !Ref PublicApplicationLoadBalancer
Port: 443
Protocol: HTTPS
PublicApplicationLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
Subnets:
!If
[ NumberOfSubnets1,
[ !Select [ 0, !Ref Subnet ] ],
!If
[ NumberOfSubnets2,
[ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ] ],
!If
[ NumberOfSubnets3,
[ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ] ],
!If
[ NumberOfSubnets4,
[ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ] ],
!If
[ NumberOfSubnets5,
[ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ], !Select [ 4, !Ref Subnet ] ],
[ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ], !Select [ 4, !Ref Subnet ], !Select [ 5, !Ref Subnet ] ]
]
]
]
]
]
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: 60
SecurityGroups:
- !Ref PublicAlbSecurityGroup
Tags:
- Key: Name
Value: !Join [ '', [ 'Public ALB / ', !Ref 'AWS::StackName' ] ]
PublicAlbTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckPath: /README.txt
HealthCheckTimeoutSeconds: 5
Name: !Join [ '', [ 'PublicALB-', !Ref Vpc ] ]
Port: 80
Protocol: HTTP
Tags:
- Key: Name
Value: !Join [ '', [ 'Public ALB / ', !Ref 'AWS::StackName' ] ]
UnhealthyThresholdCount: 5
VpcId: !Ref Vpc
Outputs:
PublicAlbTargetGroupArn:
Value:
!Ref PublicAlbTargetGroup
PublicAlbCanonicalHostedZoneId:
Value:
!GetAtt PublicApplicationLoadBalancer.CanonicalHostedZoneID
PublicAlbDnsName:
Value:
!GetAtt PublicApplicationLoadBalancer.DNSName
PublicAlbFullName:
Value:
!GetAtt PublicApplicationLoadBalancer.LoadBalancerFullName
PublicAlbHostname:
Value:
!If [ NoSslCertificate, !Join [ '', [ 'http://', !GetAtt PublicApplicationLoadBalancer.DNSName ] ], !Join [ '', [ 'https://', !GetAtt PublicApplicationLoadBalancer.DNSName ] ] ]
SslCertificate:
Value:
!If [ SslCertificate, True, False ]