forked from vanderbilt-redcap/redcap-aws-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00-master-rc.yaml
544 lines (506 loc) · 18.3 KB
/
00-master-rc.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
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License.
# A copy of the License is located at
# http://aws.amazon.com/apache2.0/
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions and limitations under the License.
AWSTemplateFormatVersion: 2010-09-09
Description: Stack to deploy a highly available, elastic, scalable REDCap environment. This master stack launches multiple nested stacks for different tiers.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: General AWS
Parameters:
- EC2KeyName
- AccessCidr
- Label:
default: DNS and SSL
Parameters:
- EBEndpoint
- UseRoute53Boolean
- UseACMBoolean
- HostedZoneIda
- HostedZoneName
- DomainName
- Label:
default: 'Email config - using AWS Simple Email Service (SES)'
Parameters:
- SESUsername
- SESPassword
- SESRegion
- Label:
default: Database Tier
Parameters:
- MultiAZDatabase
- DatabaseInstanceType
- DatabaseMasterPassword
- Label:
default: Web Tier
Parameters:
- WebInstanceType
- WebAsgMax
- WebAsgMin
- PHPVersion
- Label:
default: 'REDCap Application Source'
Parameters:
- S3orAPI
- RedcapUname
- RedcapPword
- Redcapver
- RedcapS3Bucket
- RedcapS3Key
- RedcapS3BucketRegion
- Label:
default: VPC Networking (changing this is optional)
Parameters:
- VPCcidr
- p1cidr
- p2cidr
- a1cidr
- a2cidr
- d1cidr
- d2cidr
ParameterLabels:
EC2KeyName:
default: EC2 Key Pair
AccessCidr:
default: Limit access to IP address range?
EBEndpoint:
default: Elastic Beanstalk Endpoint Name
UseRoute53Boolean:
default: Use Route 53?
UseACMBoolean:
default: Use AWS Certificate Manager?
HostedZoneIda:
default: Route53 Hosted Zone ID
HostedZoneName:
default: Hosted Zone
DomainName:
default: Site Domain
SESUsername:
default: SES Username
SESPassword:
default: SES Password
SESRegion:
default: SES Region
MultiAZDatabase:
default: Use Primary and Standby Database Instances?
DatabaseInstanceType:
default: DB Instance Class
DatabaseMasterPassword:
default: 'DB Master Password & initial password for REDCap user "redcap_admin"'
WebAsgMax:
default: Maximum REDCap Instances
WebAsgMin:
default: Minimum REDCap Instances
WebInstanceType:
default: Web Tier Instance Type
PHPVersion:
default: PHP Version
S3orAPI:
default: Download REDCap automatically?
RedcapUname:
default: REDCap Community Username
RedcapPword:
default: REDCap Community Password
Redcapver:
default: REDCap version
RedcapS3Bucket:
default: S3 Bucket
RedcapS3Key:
default: S3 Key
RedcapS3BucketRegion:
default: S3 Bucket Region
VPCcidr:
default: VPC CIDR Range
p1cidr:
default: Public Subnet A CIDR Range
p2cidr:
default: Public Subnet B CIDR Range
a1cidr:
default: Application Subnet A CIDR Range
a2cidr:
default: Application Subnet B CIDR Range
d1cidr:
default: Database Subnet A CIDR Range
d2cidr:
default: Database Subnet B CIDR Range
Parameters:
EC2KeyName:
ConstraintDescription: Must be letters (upper or lower), numbers, and special characters.
Description: '[ REQUIRED ] Name of an EC2 KeyPair. Your bastion & Web instances will launch with this KeyPair. To create a KeyPair, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#having-ec2-create-your-key-pair'
Type: AWS::EC2::KeyPair::KeyName
AccessCidr:
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Description: 'The CIDR IP range that is permitted to access your REDCap servers. Note: A value of 0.0.0.0/0 will allow access from ANY IP address.'
Type: String
Default: 0.0.0.0/0
EBEndpoint:
AllowedPattern: ^([a-zA-Z0-9-])*$
Description: '[ REQUIRED ] The unique name to use for your Elastic Beanstalk URL (will be rendered http://(EBEndpoint).(region).elasticbeanstalk.com). You can use the "nslookup" to see if an endpoint is in use.'
ConstraintDescription: 'This name must be between 4 and 40 characters and contain only letters, numbers, and/or a hyphen'
MaxLength: 40
MinLength: 4
Type: String
UseRoute53Boolean:
AllowedValues:
- true
- false
Default: false
Description: Specifies whether a record set should be created in Route 53 for your REDCap domain name. If not, you will recieve a default Elastic Beanstalk DNS name (e.g. redcap.us-east-1.elasticbeanstalk.com).
Type: String
UseACMBoolean:
AllowedValues:
- true
- false
Default: false
Description: '[ Requires Route53 ] Specifies whether an SSL certificate should be generated for your domain name using AWS Certificate Manager (ACM). If one is not generated, HTTP will be used and an SSL certificate can be applied after deployment.'
Type: String
HostedZoneIda:
Description: '[ Optional, only if using Route53 ] The Route 53 hosted zone ID to create the domain in (e.g. Z2FDTNDATAQYW2).'
Type: String
HostedZoneName:
AllowedPattern: ^$|(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
Description: '[ Optional, only if using Route53 ] The Route 53 hosted zone name to create the domain in (e.g. example.edu).'
Type: String
DomainName:
AllowedPattern: ^([a-zA-Z0-9-])*$
Description: '[ Optional, only if using Route53 ] The sub-domain name of the REDCap website. This sub-domain will be prepended your specified Hosted Zone (e.g. redcap in redcap.example.edu).'
Type: String
SESUsername:
Type: String
Description: '[ Required ] Username to use for authentication to SES.'
SESPassword:
Type: String
Description: '[ Required ] Password to use for authentication to SES.'
NoEcho: true
SESRegion:
Type: String
AllowedValues:
- us-east-2
- us-east-1
- us-west-1
- us-west-2
- af-south-1
- ap-south-1
- ap-northeast-1
- ap-northeast-2
- ap-northeast-3
- ap-southeast-1
- ap-southeast-2
- ca-central-1
- eu-central-1
- eu-west-1
- eu-west-2
- eu-west-3
- eu-north-1
- sa-east-1
- us-gov-west-1
Description: Region where you configured your SES credentials.
MultiAZDatabase:
AllowedValues:
- true
- false
Default: false
Description: Specifies whether to deploy the AWS Aurora MySQL Database in a Multi-AZ configuration.
Type: String
DatabaseInstanceType:
AllowedValues:
- db.t3.small
- db.t3.medium
- db.t3.large
- db.r5.large
- db.r5.xlarge
- db.r5.2xlarge
- db.r5.4xlarge
- db.r5.8xlarge
- db.r5.16xlarge
- db.r5.24xlarge
ConstraintDescription: Must be a valid RDS instance class.
Default: db.t3.small
Description: The Amazon RDS database instance class (determines processing power and memory capacity of the database).
Type: String
DatabaseMasterPassword:
AllowedPattern: ^([a-zA-Z0-9~#%^*_+,-])*$
ConstraintDescription: Must have a length of 8-41 and be letters (upper or lower), numbers, and/or these special characters ~#%^*_+,-
Description: '[ Required ] The Amazon RDS master password (this will also be used as the initial temp password for the REDCap user "redcap_admin"). Letters, numbers, and/or these special characters ~#%^*_+,-'
MaxLength: 41
MinLength: 8
NoEcho: true
Type: String
WebInstanceType:
AllowedValues:
- t3.nano
- t3.micro
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3.2xlarge
- m5.large
- m5.xlarge
- m5.2xlarge
- m5.4xlarge
- m5.12xlarge
- m5.24xlarge
- c5.large
- c5.xlarge
- c5.2xlarge
- c5.4xlarge
- c5.9xlarge
- c5.18xlarge
- r5.large
- r5.xlarge
- r5.2xlarge
- r5.4xlarge
- r5.8xlarge
- r5.16xlarge
- r5.24xlarge
ConstraintDescription: Must be a valid Amazon EC2 instance type.
Default: t3.micro
Description: The Amazon EC2 instance type for your web instances.
Type: String
WebAsgMax:
AllowedPattern: ^((?!0$)[1-2]?[0-9]|30)$
ConstraintDescription: Must be a number between 1 and 30.
Default: 2
Description: Specifies the maximum number of EC2 instances in the Web Autoscaling Group. Must be greater than or equal to the Minimum REDCap Instances.
Type: String
WebAsgMin:
AllowedPattern: ^([0-0]?[0-9]|10)$
ConstraintDescription: Must be a number between 0 and 10.
Default: 2
Description: Specifies the minimum number of EC2 instances in the Web Autoscaling Group. A value of >1 will a highly available environment by placing instances in multiple availability zones.
Type: String
PHPVersion:
AllowedValues:
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
Default: 8.1
Description: The version of PHP to use with REDCap. PHP 8.1 is recommended.
Type: String
S3orAPI:
Description: "Download REDCap automatically or provide it in S3?"
Type: String
AllowedValues:
- "Provide in S3"
- "Download using REDCap API"
Default: "Download using REDCap API"
RedcapS3Bucket:
Description: "The name of the S3 bucket that contains your REDCap source zip file (e.g. myredcapsourcefiles) (used if 'Provide in S3' is selected)"
Type: String
RedcapS3Key:
Description: "The S3 key name - the file name of the REDCap source file (e.g. redcap8.6.0.zip) located inside the bucket provided above (used if 'Provide in S3' is selected)"
Type: String
RedcapS3BucketRegion:
Description: "AWS Region of the S3 bucket that contains your REDCap source zip file (used if 'Provide in S3' is selected)"
Type: String
AllowedValues:
- us-east-2
- us-east-1
- us-west-1
- us-west-2
- af-south-1
- ap-south-1
- ap-northeast-1
- ap-northeast-2
- ap-northeast-3
- ap-southeast-1
- ap-southeast-2
- ca-central-1
- eu-central-1
- eu-west-1
- eu-west-2
- eu-west-3
- eu-north-1
- sa-east-1
- us-gov-west-1
Default: us-east-1
RedcapUname:
Description: Your REDCap Community Username (used if 'Download using REDCap API' is selected)
Type: String
RedcapPword:
Description: Your REDCap Community Password (used if 'Download using REDCap API' is selected)
Type: String
NoEcho: true
Redcapver:
Description: The version of REDCap you want to install, 'latest' for latest version (used if 'Download using REDCap API' is selected)
Type: String
Default: latest
VPCcidr:
Description: (optional to change) CIDR IP Range for your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.0.0/16
p1cidr:
Description: (optional to change) CIDR IP Range for the public subnet in AZ 'a' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.0.0/24
p2cidr:
Description: (optional to change) CIDR IP Range for the public subnet in AZ 'b' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.1.0/24
a1cidr:
Description: (optional to change) CIDR IP Range for the application subnet in AZ 'a' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.2.0/24
a2cidr:
Description: (optional to change) CIDR IP Range for the application subnet in AZ 'b' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.3.0/24
d1cidr:
Description: (optional to change) CIDR IP Range for the database subnet in AZ 'b' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.4.0/24
d2cidr:
Description: (optional to change) CIDR IP Range for the database subnet in AZ 'b' of your REDCap VPC.
AllowedPattern: ^(([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])(\/([0-9]|[1-2][0-9]|3[0-2]))$
Type: String
Default: 10.1.5.0/24
Conditions:
DeployRoute53:
!Equals [ true, !Ref UseRoute53Boolean ]
DeployACM: !And
- !Equals [ true, !Ref UseACMBoolean ]
- !Condition DeployRoute53
Resources:
certificate:
Condition: DeployACM
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: !Join ['', [!Ref DomainName, '.', !Ref HostedZoneName]]
DomainValidationOptions:
- HostedZoneId: !Ref HostedZoneIda
DomainName: !Join ['', [!Ref DomainName, '.', !Ref HostedZoneName]]
ValidationMethod: DNS
VPCStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/redcap-aws-cloudformation/01-rc-vpc.yaml
Parameters:
AccessCidr: !Ref 'AccessCidr'
RedcapS3Bucket: !Ref 'RedcapS3Bucket'
UseACMBoolean: !Ref 'UseACMBoolean'
UseRoute53Boolean: !Ref 'UseRoute53Boolean'
VPCcidr: !Ref VPCcidr
p1cidr: !Ref p1cidr
p2cidr: !Ref p2cidr
a1cidr: !Ref a1cidr
a2cidr: !Ref a2cidr
d1cidr: !Ref d1cidr
d2cidr: !Ref d2cidr
redcapelasticbeanstalk:
DependsOn: [ VPCStack ]
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
EBBucket: !Join [ "", [ !Ref "AWS::AccountId", '-', !Select [ 1, !Split [ '-', !GetAtt 'VPCStack.Outputs.SubnetPublicA'] ], '-redcapebapp' ] ]
SESUsername:
!Ref SESUsername
SESPassword:
!Ref SESPassword
SESRegion:
!Ref SESRegion
DatabaseMasterPassword:
!Ref DatabaseMasterPassword
DatabaseInstanceType:
!Ref DatabaseInstanceType
MultiAZDatabase:
!Ref MultiAZDatabase
SslCertificate:
!If [ DeployACM, !Ref certificate, '' ]
WebAsgMax:
!Ref WebAsgMax
WebAsgMin:
!Ref WebAsgMin
WebInstanceType:
!Ref WebInstanceType
PHPVersion:
!Ref PHPVersion
S3AccessKey:
!GetAtt 'VPCStack.Outputs.S3AccessKey'
S3SecretKey:
!GetAtt 'VPCStack.Outputs.S3SecretKey'
S3FileRepositoryBucket: !Join [ "", [ !Ref "AWS::AccountId", '-', !Select [ 1, !Split [ '-', !GetAtt 'VPCStack.Outputs.SubnetPublicA'] ], '-redcaprepository' ] ]
EBEndpoint:
!Ref EBEndpoint
UseRoute53Boolean:
!Ref UseRoute53Boolean
UseACMBoolean:
!Ref UseACMBoolean
HostedZoneName:
!If [ DeployRoute53, !Ref HostedZoneName, '' ]
DomainName:
!If [ DeployRoute53, !Ref DomainName, '' ]
S3orAPI:
!Ref S3orAPI
RedcapS3Bucket:
!Ref RedcapS3Bucket
RedcapS3Key:
!Ref RedcapS3Key
RedcapS3BucketRegion:
!Ref RedcapS3BucketRegion
RedcapUname:
!Ref RedcapUname
RedcapPword:
!Ref RedcapPword
Redcapver:
!Ref Redcapver
EC2KeyName:
!Ref EC2KeyName
VPCId:
!GetAtt 'VPCStack.Outputs.VPCId'
SubnetPublicA:
!GetAtt 'VPCStack.Outputs.SubnetPublicA'
SubnetPublicB:
!GetAtt 'VPCStack.Outputs.SubnetPublicB'
SubnetAppA:
!GetAtt 'VPCStack.Outputs.SubnetAppA'
SubnetAppB:
!GetAtt 'VPCStack.Outputs.SubnetAppB'
SubnetDataA:
!GetAtt 'VPCStack.Outputs.SubnetDataA'
SubnetDataB:
!GetAtt 'VPCStack.Outputs.SubnetDataB'
SGPublic:
!GetAtt 'VPCStack.Outputs.SGPublic'
SGApp:
!GetAtt 'VPCStack.Outputs.SGApp'
SGData:
!GetAtt 'VPCStack.Outputs.SGData'
EBServiceRole:
!GetAtt 'VPCStack.Outputs.EBServiceRole'
EBInstanceProfile:
!GetAtt 'VPCStack.Outputs.EBInstanceProfile'
TempEC2InstanceProfile:
!GetAtt 'VPCStack.Outputs.TempEC2InstanceProfile'
TemplateURL: https://s3.amazonaws.com/redcap-aws-cloudformation/02-rc-elasticbeanstalk.yaml
route53:
Condition: DeployRoute53
DependsOn: redcapelasticbeanstalk
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
DnsEndpoint:
!Join ['', [!Ref EBEndpoint, '.', !Ref 'AWS::Region', '.elasticbeanstalk.com']]
HostedZoneId:
!Ref HostedZoneIda
HostedZoneName:
!Ref HostedZoneName
DomainName:
!Ref DomainName
TemplateURL: https://s3.amazonaws.com/redcap-aws-cloudformation/03-rc-route53.yaml
Outputs:
REDCapURL:
Value: !If [DeployRoute53, !If [DeployACM, !Join ['', ['https://', !Ref DomainName, '.', !Ref HostedZoneName, '/']], !Join ['', ['http://', !Ref DomainName, '.', !Ref HostedZoneName, '/']]], !Join ['', ['http://', !Ref EBEndpoint, '.', !Ref 'AWS::Region', '.elasticbeanstalk.com']]]