-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsample_vpc_template.yaml
More file actions
295 lines (293 loc) · 8.97 KB
/
Copy pathsample_vpc_template.yaml
File metadata and controls
295 lines (293 loc) · 8.97 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
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
AWSTemplateFormatVersion: 2010-09-09
Description: "Prepare sample environment by adding a VPC, subnets, security-groups, etc."
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Environment"
Parameters:
- Prefix
- Label:
default: "VPC Configuration"
Parameters:
- Zone1
- Zone2
- Label:
default: "EC2 Configuration"
Parameters:
- KeyPairName
ParameterLabels:
Prefix:
default: "Prefix"
Zone1:
default: "Availability Zone 1"
Zone2:
default: "Availability Zone 2"
KeyPairName:
default: "EC2 Key Pair"
Parameters:
Prefix:
Description: Name tag prefix that's added to all the resources
Type: String
Default: spoke1
Zone1:
Description: Availability Zone 1
Type: AWS::EC2::AvailabilityZone::Name
Default: us-east-1a
Zone2:
Description: Availability Zone 2
Type: AWS::EC2::AvailabilityZone::Name
Default: us-east-1b
KeyPairName:
Description: SSH Keypair Name to use for the App EC2 Instance
Type: AWS::EC2::KeyPair::KeyName
Mappings:
AppImage:
us-east-1:
ubuntu2204: ami-0fc5d935ebf8bc3bc
us-east-2:
ubuntu2204: ami-0e83be366243f524a
us-west-1:
ubuntu2204: ami-0cbd40f694b804622
us-west-2:
ubuntu2204: ami-0efcece6bed30fd98
ca-central-1:
ubuntu2204: ami-06873c81b882339ac
eu-central-1:
ubuntu2204: ami-06dd92ecc74fdfb36
eu-north-1:
ubuntu2204: ami-0fe8bec493a81c7da
eu-west-1:
ubuntu2204: ami-0694d931cee176e7d
eu-west-2:
ubuntu1804: ami-0505148b3591e4c07
eu-west-3:
ubuntu1804: ami-00983e8a26e4c9bd9
Resources:
SampleVPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: 10.0.0.0/16
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-vpc"
SampleInternetGateway:
Type: "AWS::EC2::InternetGateway"
Properties:
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-igw"
SampleIGWAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: SampleVPC
InternetGatewayId:
Ref: SampleInternetGateway
SampleAppsSubnet1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Ref: Zone1
VpcId:
Ref: SampleVPC
CidrBlock: 10.0.0.0/24
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z1-apps"
SampleAppsSubnet2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Ref: Zone2
VpcId:
Ref: SampleVPC
CidrBlock: 10.0.3.0/24
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z2-apps"
RouteTableApps1:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: SampleVPC
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z1-apps"
RouteTableApps2:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: SampleVPC
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z2-apps"
InternetRouteApps1:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: SampleInternetGateway
RouteTableId:
Ref: RouteTableApps1
InternetRouteApps2:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: SampleInternetGateway
RouteTableId:
Ref: RouteTableApps2
AppsSubnetRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: RouteTableApps1
SubnetId:
Ref: SampleAppsSubnet1
AppsSubnetRouteTableAssociation2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: RouteTableApps2
SubnetId:
Ref: SampleAppsSubnet2
SecurityGroupApps:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName:
Fn::Sub: "${Prefix}-apps"
GroupDescription: "Security group for the apps, used by applications"
VpcId:
Ref: SampleVPC
SecurityGroupEgress:
- IpProtocol: -1
FromPort: "0"
ToPort: "0"
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: "22"
ToPort: "22"
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: "80"
ToPort: "80"
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: "8000"
ToPort: "8000"
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: "443"
ToPort: "443"
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-apps"
SpokeIAMRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: "${Prefix}-spoke-role"
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: spoke-iam-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "*"
Resource: "*"
SpokeInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
InstanceProfileName:
Fn::Sub: "${Prefix}-instance-profile"
Path: /
Roles:
- !Ref SpokeIAMRole
AppInstance1:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
Ref: Zone1
ImageId:
Fn::FindInMap: [AppImage, Ref: "AWS::Region", ubuntu2204]
InstanceType: t3a.small
IamInstanceProfile:
Ref: SpokeInstanceProfile
KeyName:
Ref: KeyPairName
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: 0
SubnetId:
Ref: SampleAppsSubnet1
GroupSet:
- Ref: SecurityGroupApps
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z1-app"
AppInstance2:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
Ref: Zone2
ImageId:
Fn::FindInMap: [AppImage, Ref: "AWS::Region", ubuntu2204]
InstanceType: t3a.small
IamInstanceProfile:
Ref: SpokeInstanceProfile
KeyName:
Ref: KeyPairName
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: 0
SubnetId:
Ref: SampleAppsSubnet2
GroupSet:
- Ref: SecurityGroupApps
Tags:
- Key: Name
Value:
Fn::Sub: "${Prefix}-z2-app"
Outputs:
AppInstance1Ip:
Description: "AppInstance 1 IP"
Value:
Fn::Join:
[
", ",
[
Fn::GetAtt: AppInstance1.PrivateIp,
Fn::GetAtt: AppInstance1.PublicIp,
],
]
AppInstance2Ip:
Description: "AppInstance 2 IP"
Value:
Fn::Join:
[
", ",
[
Fn::GetAtt: AppInstance2.PrivateIp,
Fn::GetAtt: AppInstance2.PublicIp,
],
]