forked from zconsulting-co/aws-moodle-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-rds.yaml
237 lines (227 loc) · 7.52 KB
/
03-rds.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
---
AWSTemplateFormatVersion: 2010-09-09
Description: Reference Architecture to host Moodle on AWS - Creates RDS Aurora mysql database cluster
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Database Parameters
Parameters:
- DatabaseInstanceType
# - DatabaseMasterUsername
# - DatabaseMasterPassword
- DatabaseName
- DatabaseEncrpytedBoolean
- DatabaseCmk
- DatabaseSecurityGroup
- NumberOfSubnets
- Subnet
ParameterLabels:
DatabaseEncrpytedBoolean:
default: Encrypted DB Cluster
DatabaseCmk:
default: AWS KMS Customer Master Key (CMK) to encrypt DB
DatabaseInstanceType:
default: DB Instance Class
# DatabaseMasterUsername:
# default: DB Master Username
# DatabaseMasterPassword:
# default: DB Master Password
DatabaseName:
default: DB Name
DatabaseSecurityGroup:
default: DB Security Group
NumberOfSubnets:
default: Number of subnets
Subnet:
default: Subnets
Parameters:
DatabaseEncrpytedBoolean:
AllowedValues:
- true
- false
Default: True
Description: Indicates whether the DB instances in the cluster are encrypted.
Type: String
DatabaseCmk:
Description: AWS KMS Customer Master Key (CMK) to encrypt database cluster
Type: String
DatabaseInstanceType:
AllowedValues:
- db.t3.small
- db.r4.large
- db.r4.xlarge
- db.r4.2xlarge
- db.r4.4xlarge
- db.r4.8xlarge
- db.r4.16xlarge
ConstraintDescription: Must be a valid RDS instance class.
Default: db.t3.small
Description: The Amazon RDS database instance class.
Type: String
# DatabaseMasterUsername:
# AllowedPattern: ^([a-zA-Z0-9]*)$
# Description: The Amazon RDS master username.
# ConstraintDescription: Must contain only alphanumeric characters and be at least 8 characters.
# MaxLength: 16
# MinLength: 1
# Type: String
# DatabaseMasterPassword:
# AllowedPattern: ^([a-z0-9A-Z`~!#$%^&*()_+,\\-])*$
# ConstraintDescription: Must be letters (upper or lower), numbers, and these special characters '_'`~!#$%^&*()_+,-
# Description: The Amazon RDS master password.
# MaxLength: 41
# MinLength: 8
# NoEcho: true
# Type: String
MyRDSInstanceSecretArn:
Type: String
DatabaseName:
AllowedPattern: ^([a-zA-Z0-9]*)$
Description: The Amazon RDS master database name.
Type: String
DatabaseSecurityGroup:
Description: Select the database security group.
Type: AWS::EC2::SecurityGroup::Id
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
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>
Conditions:
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
UseAWS-ManagedCMK:
!Equals ['', !Ref DatabaseCmk]
Resources:
DatabaseCluster:
Type: AWS::RDS::DBCluster
Properties:
BackupRetentionPeriod: 30
DatabaseName: !Ref DatabaseName
DBSubnetGroupName: !Ref DataSubnetGroup
Engine: aurora-mysql
DBClusterParameterGroupName: default.aurora-mysql5.7
KmsKeyId:
!If [ UseAWS-ManagedCMK, !Ref 'AWS::NoValue', !Ref DatabaseCmk ]
MasterUsername: !Join ['', ['{{resolve:secretsmanager:', !Ref MyRDSInstanceSecretArn, ':SecretString:username}}' ]]
MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', !Ref MyRDSInstanceSecretArn, ':SecretString:password}}' ]]
Port: 3306
StorageEncrypted: !Ref DatabaseEncrpytedBoolean
Tags:
- Key: Name
Value: !Join [ '', [ 'Moodle / ', !Ref 'AWS::StackName' ] ]
VpcSecurityGroupIds:
- !Ref DatabaseSecurityGroup
DatabaseInstance0:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
Properties:
AllowMajorVersionUpgrade: false
AutoMinorVersionUpgrade: true
DBClusterIdentifier: !Ref DatabaseCluster
DBInstanceClass: !Ref DatabaseInstanceType
DBSubnetGroupName: !Ref DataSubnetGroup
Engine: aurora-mysql
Tags:
- Key: Name
Value: !Join [ '', [ 'Moodle / ', !Ref 'AWS::StackName' ] ]
DatabaseInstance1:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
Properties:
AllowMajorVersionUpgrade: false
AutoMinorVersionUpgrade: true
DBClusterIdentifier: !Ref DatabaseCluster
DBInstanceClass: !Ref DatabaseInstanceType
DBSubnetGroupName: !Ref DataSubnetGroup
Engine: aurora-mysql
Tags:
- Key: Name
Value: !Join [ '', [ 'Moodle / ', !Ref 'AWS::StackName' ] ]
DataSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: RDS Database Subnet Group for Moodle
SubnetIds:
!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 ] ]
]
]
]
]
]
Tags:
- Key: Name
Value: !Join [ '', [ 'Moodle / ', !Ref 'AWS::StackName' ] ]
Outputs:
DatabaseCluster:
Value: !Ref DatabaseCluster
DatabaseName:
Value: !Ref DatabaseName
DatabaseInstance0:
Value: !Ref DatabaseInstance0
DatabaseInstance1:
Value: !Ref DatabaseInstance1
DataSubnetGroup:
Value: !Ref DataSubnetGroup
DatabaseClusterEndpointAddress:
Value: !GetAtt DatabaseCluster.Endpoint.Address