-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg-database-template-06.yaml
170 lines (157 loc) · 4.73 KB
/
pg-database-template-06.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
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create a DB subnet group and MYSQL Database"
Parameters:
PrivateSubnet01:
Type: String
Description: The subnet for the DB cluster
PrivateSubnet02:
Type: String
Description: The subnet for the DB cluster
PrivateSubnet03:
Type: String
Description: The subnet for the DB cluster
ProductID:
Description: ""
Type: String
Default: example
Environment:
Description: ""
Type: String
Default: dev
Role:
Description: ""
Type: String
Default: core
DatabasePort:
Type: String
Default: 5432
MasterUsername:
Type: String
Default: "saif"
MasterUserPassword:
Type: String
Default: "saif-pass1word2.com"
NoEcho: true
DatabaseName:
Type: String
Default: coredb
Resources:
SubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: !Sub "${AWS::StackName}-DBSubnetGroup"
SubnetIds:
- !Ref PrivateSubnet01
- !Ref PrivateSubnet02
- !Ref PrivateSubnet03
RdsSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: !Sub "${AWS::StackName}-SecurityGroup - allow access to rds"
VpcId:
"vpc-0d2f42a0b63b821ce"
# Fn::ImportValue:
# Fn::Sub: "${NetworkStack}:VPCId"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: !Ref DatabasePort
ToPort: !Ref DatabasePort
# GroupId: !Ref DataSourceSecurityGroup
CidrIp: 0.0.0.0/0
Description: "Allow external connections from gui clients"
# - IpProtocol: tcp
# FromPort: "5432"
# ToPort: "5432"
# SourceSecurityGroupId: !ImportValue
# "Fn::Sub": "${NetworkStack}:FargateContainerSecurityGroup"
Tags:
- Key: ProductID
Value: !Ref ProductID
- Key: Environment
Value: !Ref Environment
- Key: Role
Value: !Ref Role
# https://github.com/widdix/aws-cf-templates/blob/1d4540427500c1d70413b33562aa441700323dc7/state/rds-aurora.yaml#L297
DBInstance:
Type: AWS::RDS::DBInstance
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
DBInstanceClass: db.t2.micro
Engine: postgres
EngineVersion: "12.12"
PubliclyAccessible: true
MultiAZ: false
AllocatedStorage: 10
DBSubnetGroupName: !Ref SubnetGroup
Port: !Ref DatabasePort
MasterUsername: !Ref MasterUsername
MasterUserPassword: !Ref MasterUserPassword
DBName: !Ref DatabaseName # database to create when the DB instance is created
Tags:
- Key: ProductID
Value: !Ref ProductID
- Key: Environment
Value: !Ref Environment
- Key: Role
Value: !Ref Role
SSMEndpointAddress:
Type: AWS::SSM::Parameter
Properties:
Description: "EndpointAddress"
Name: !Sub "/${ProductID}/${Environment}/database/${Role}/EndpointAddress"
Value: !GetAtt "DBInstance.Endpoint.Address"
Type: String
# SSMReadEndpointAddress:
# Type: AWS::SSM::Parameter
# Properties:
# Description: "ReadEndpointAddress"
# Name: !Sub "/${ProductID}/${Environment}/database/${Role}/ReadEndpointAddress"
# Value: !GetAtt "DBInstance.ReadEndpoint.Address"
# Type: String
SSMMasterUsername:
Type: AWS::SSM::Parameter
Properties:
Description: "MasterUsername"
Name: !Sub "/${ProductID}/${Environment}/database/${Role}/MasterUsername"
Value: !Ref MasterUsername
Type: String
SSMMasterUserPassword:
Type: AWS::SSM::Parameter
Properties:
Description: "MasterUserPassword"
Name: !Sub "/${ProductID}/${Environment}/database/${Role}/MasterUserPassword"
Value: !Ref MasterUserPassword
Type: String
SSMDatabaseName:
Type: AWS::SSM::Parameter
Properties:
Description: "DatabaseName"
Name: !Sub "/${ProductID}/${Environment}/database/${Role}/DatabaseName"
Value: !Ref DatabaseName
Type: String
Outputs:
ClusterAddress:
Value: !GetAtt "DBInstance.Endpoint.Address"
Export:
Name: !Sub "${AWS::StackName}::ClusterAddress"
# ClusterReadAddress:
# Value: !GetAtt "DBInstance.ReadEndpoint.Address"
# Export:
# Name: !Sub "${AWS::StackName}::ClusterReadAddress"
DatabasePort:
Value: !Ref DatabasePort
Export:
Name: !Sub "${AWS::StackName}::DatabasePort"
MasterUsername:
Value: !Ref MasterUsername
Export:
Name: !Sub "${AWS::StackName}::MasterUsername"
MasterUserPassword:
Value: !Ref MasterUserPassword
Export:
Name: !Sub "${AWS::StackName}::MasterUserPassword"
DatabaseName:
Value: !Ref DatabaseName
Export:
Name: !Sub "${AWS::StackName}::DatabaseName"