forked from thinegan/cloudformation-project1
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebapp-rds.yaml
More file actions
145 lines (119 loc) · 3.69 KB
/
webapp-rds.yaml
File metadata and controls
145 lines (119 loc) · 3.69 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
# Note, the development RDS is not Multi-AZ supported
# Only the production RDS is Multi-AZ supported
# The default RDS Username/DBName/Password is for testing purpose only.
#
---
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Database stack creation prerequisite:
- RDS Security Group
Parameters:
PMServerEnv:
Description: "Server Environment name."
ConstraintDescription: "Choose an Environment from the drop down"
Type: "String"
AllowedValues:
- "dev"
- "staging"
- "prod"
PMPrivateSubnets:
Description: "Subnets to launch instances into"
Type: "List<AWS::EC2::Subnet::Id>"
PMRDSSG:
Description: "Select the Security Group to use for the ELB"
Type: "AWS::EC2::SecurityGroup::Id"
DatabaseUser:
NoEcho: 'true'
Type: "String"
Description: "Database admin account name"
MinLength: '5'
MaxLength: '16'
AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*"
ConstraintDescription: "Name must begin with a letter and contain only alphanumeric characters."
DatabasePassword:
NoEcho: 'true'
Type: "String"
Description: "Database admin account password"
MinLength: '6'
MaxLength: '41'
AllowedPattern: "[a-zA-Z0-9]*"
ConstraintDescription: "Password must contain only alphanumeric characters."
DatabaseName:
Type: "String"
Description: "Database name"
MinLength: '1'
MaxLength: '30'
AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*"
ConstraintDescription: "Name must begin with a letter and contain only alphanumeric characters."
DatabaseSize:
Type: "String"
Description: "Database storage size in gigabytes (GB)"
MinLength: '1'
AllowedPattern: "[5-9][0-9]*"
ConstraintDescription: "Enter a size of at least 5 GB"
DatabaseEngine:
Type: "String"
Description: "Database engine, MySQL or PostgreSQL"
ConstraintDescription: "Choose an engine from the drop down"
AllowedValues:
- "mysql"
- "postgres"
DatabaseInstanceClass:
Type: "String"
Description: "Database instance class, e.g. db.t2.micro (free tier)"
ConstraintDescription: "Choose an instance class from the drop down"
AllowedValues:
- "db.t2.micro"
- "db.t2.small"
- "db.t2.medium"
- "db.t2.large"
- "db.m4.large"
- "db.m4.xlarge"
- "db.m4.2xlarge"
- "db.m4.4xlarge"
- "db.m4.10xlarge"
- "db.r3.large"
- "db.r3.xlarge"
- "db.r3.2xlarge"
- "db.r3.4xlarge"
- "db.r3.8xlarge"
####### Condition Setup #######
Conditions:
UseProdEnv: !Equals [ !Ref "PMServerEnv", "prod" ]
Resources:
Database:
Type: "AWS::RDS::DBInstance"
Properties:
DBSubnetGroupName: !Ref "DbSubnetGroup"
VPCSecurityGroups:
- Ref: "PMRDSSG"
Engine: !Ref "DatabaseEngine"
DBName: !Ref "DatabaseName"
MasterUsername: !Ref "DatabaseUser"
MasterUserPassword: !Ref "DatabasePassword"
DBInstanceClass: !Ref "DatabaseInstanceClass"
AllocatedStorage: !Ref "DatabaseSize"
StorageType: "gp2"
MultiAZ: !If [ "UseProdEnv", 'true', 'false' ]
DbSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: !Sub "${PMServerEnv} RDS DB subnet group"
SubnetIds:
Ref: "PMPrivateSubnets"
Outputs:
RdsDbId:
Description: "RDS Database ID"
Value: !Ref "Database"
DbName:
Description: "RDS Database Name"
Value: !Ref "DatabaseName"
RdsDbURL:
Description: "RDS Database URL"
Value: !GetAtt "Database.Endpoint.Address"
DbUser:
Description: "RDS Database admin account user"
Value: !Ref "DatabaseUser"
DbPassword:
Description: "RDS Database admin account password"
Value: !Ref "DatabasePassword"