-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02-environment.yml
162 lines (152 loc) · 4.25 KB
/
02-environment.yml
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
Parameters:
Vpc:
Type: AWS::EC2::VPC::Id
PrivateSubnets:
Type: List<AWS::EC2::Subnet::Id>
PublicSubnets:
Type: List<AWS::EC2::Subnet::Id>
DatabaseInstanceType:
Type: String
Default: db.t2.micro
AllowedValues:
- db.t2.micro
- db.t2.small
- db.t2.medium
- db.t2.large
DatabaseAllocatedStorage:
Type: Number
Default: 10
InstanceType:
Type: String
AllowedValues:
- t3.nano
- t3.micro
- t3.small
- t3.medium
- t3.large
Default: t3.nano
MinSize:
Type: Number
Default: 1
MaxSize:
Type: Number
Default: 2
MinValue: 2
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Network Configuration"
Parameters:
- Vpc
- PublicSubnets
- PrivateSubnets
- Label:
default: "Compute Configuration"
Parameters:
- InstanceType
- MinSize
- MaxSize
- Label:
default: "Database Configuration"
Parameters:
- DatabaseInstanceType
- DatabaseAllocatedStorage
ParameterLabels:
InstanceType:
default: Instance Type
MinSize:
default: Minimum instances
DatabaseInstanceType:
default: Instance Type
DatabaseAllocatedStorage:
default: Allocated Storage
DatabasePassword:
default: Password
Resources:
ElbSG:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: !Sub "${AWS::StackName} ELB SG"
VpcId: !Ref Vpc
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: "80"
ToPort: "80"
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub ${AWS::StackName}-ElbSG
ApplicationSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Sub "${AWS::StackName} Application SG"
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: !Sub ${AWS::StackName}-ApplicationSG
ApplicationSGIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !GetAtt ApplicationSG.GroupId
IpProtocol: "tcp"
FromPort: "80"
ToPort: "80"
SourceSecurityGroupId: !GetAtt ElbSG.GroupId
DatabaseSG:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: !Sub "${AWS::StackName} RDS SG"
VpcId: !Ref Vpc
SecurityGroupIngress:
- IpProtocol: 'tcp'
FromPort: '3306'
ToPort: '3306'
SourceSecurityGroupId: !Ref ApplicationSG
Tags:
- Key: Name
Value: !Sub ${AWS::StackName}-DatabaseSG
Secret:
Type: 'AWS::SecretsManager::Secret'
Properties:
GenerateSecretString:
SecretStringTemplate: '{"username": "root"}'
GenerateStringKey: "password"
PasswordLength: 24
ExcludeCharacters: '"@/\'
SecretRotation:
Type: "AWS::CloudFormation::Stack"
Properties:
Parameters:
AppName: !Ref AWS::StackName
ApplicationSG: !Ref ApplicationSG
Subnets: !Join [',', !Ref PrivateSubnets]
Secret: !Ref Secret
TemplateURL: https://s3-eu-west-1.amazonaws.com/sysless/demo-cloudformation/01-secret-rotation.yml
Database:
Type: "AWS::CloudFormation::Stack"
Properties:
Parameters:
AppName: !Ref AWS::StackName
DatabaseInstanceType: !Ref DatabaseInstanceType
DatabaseAllocatedStorage: !Ref DatabaseAllocatedStorage
DatabaseSG: !Ref DatabaseSG
Subnets: !Join [',', !Ref PrivateSubnets]
SecretArn: !Ref Secret
TemplateURL: https://s3-eu-west-1.amazonaws.com/sysless/demo-cloudformation/01-database.yml
Application:
Type: "AWS::CloudFormation::Stack"
Properties:
Parameters:
AppName: !Ref AWS::StackName
InstanceType: !Ref InstanceType
MinSize: !Ref MinSize
MaxSize: !Ref MaxSize
ApplicationSG: !Ref ApplicationSG
ElbSG: !Ref ElbSG
Subnets: !Join [',', !Ref PublicSubnets]
SecretArn: !Ref Secret
TemplateURL: https://s3-eu-west-1.amazonaws.com/sysless/demo-cloudformation/01-application.yml
Outputs:
DNSName:
Value: !GetAtt Application.Outputs.Url