forked from medianotion/hipaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc-management.template
executable file
·555 lines (555 loc) · 20 KB
/
vpc-management.template
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
545
546
547
548
549
550
551
552
553
554
555
AWSTemplateFormatVersion: 2010-09-09
Description: 'Provides networking configuration for a standard management VPC (qs-1nb14cqcg)'
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Region Config
Parameters:
- pRegionAZ1Name
- pRegionAZ2Name
- Label:
default: Management VPC Configuration
Parameters:
- pManagementVPCName
- pManagementCIDR
- pManagementDMZSubnetACIDR
- pManagementDMZSubnetBCIDR
- pVPCTenancy
- Label:
default: AWS Quick Start Configuration
Parameters:
- QuickStartS3URL
- QSS3BucketName
- QSS3KeyPrefix
- Label:
default: Optional Components - Bastion
Parameters:
- pCreateBastionHost
- pEC2KeyPairBastion
- pBastionInstanceType
- pBastionAmi
- pBastionSSHCIDR
ParameterLabels:
pManagementVPCName:
default: Name of Management VPC to create
pManagementCIDR:
default: CIDR block of Management VPC
pManagementDMZSubnetACIDR:
default: CIDR block of Management DMZ SubnetA
pManagementDMZSubnetBCIDR:
default: CIDR block of Management DMZ SubnetB
pVPCTenancy:
default: Instance tenancy
QuickStartS3URL:
default: Quick Start URL
QSS3BucketName:
default: Quick Start S3 Bucket Name
QSS3KeyPrefix:
default: Quick Start S3 Key Prefix
pCreateBastionHost:
default: Create Bastion Host
pEC2KeyPairBastion:
default: Bastion KeyPair
pBastionInstanceType:
default: Bastion Instance Type
pBastionAmi:
default: Bastion AMI
pBastionSSHCIDR:
default: Bastion SSH CIDR
Stack:
Value: 2
VersionDate:
Value: 20160510
Identifier:
Value: template-vpc-management
Input:
Description: CIDR blocks, VPC names, KeyName, EC2 instance size
Output:
Description: Outputs ID of all deployed resources
Parameters:
pCreateBastionHost:
Description: Should a Bastion host be created inside the DMZ Subnet(s)?
Type: String
Default: true
AllowedValues:
- true
- false
pProductionVPC:
Description: Production VPC to peer with (optional)
Type: String
Default: ''
pProductionCIDR:
Description: CIDR of Production VPC
Type: String
Default: ''
pRouteTableProdPrivate:
Description: Route Table ID for Prod VPC Private
Type: String
Default: ''
pRouteTableProdPublic:
Description: Route Table ID for Prod VPC Public
Type: String
Default: ''
pRegionAZ1Name:
Description: Availability Zone 1 Name in Region
Type: String
Default: us-east-1b
pRegionAZ2Name:
Description: Availability Zone 2 Name in Region
Type: String
Default: us-west-1c
pEC2KeyPairBastion:
Description: Name of existing EC2 key pair for BASTION hosts
Type: String
Default: ''
pBastionInstanceType:
Description: Bastion EC2 instance type
Type: String
Default: m3.large
pManagementVPCName:
Description: Management VPC Name
Type: String
Default: Management VPC
pManagementCIDR:
Description: CIDR block for Management VPC
Type: String
Default: 10.10.0.0/16
pManagementDMZSubnetACIDR:
Description: CIDR block for Management AZ-1a subnet
Type: String
Default: 10.10.10.0/24
pManagementDMZSubnetBCIDR:
Description: CIDR block for Management AZ-1b subnet
Type: String
Default: 10.10.20.0/24
pManagementPrivateSubnetACIDR:
Description: CIDR block for Management AZ-1a subnet
Type: String
Default: 10.10.10.0/24
pManagementPrivateSubnetBCIDR:
Description: CIDR block for Management AZ-1b subnet
Type: String
Default: 10.10.20.0/24
pVPCTenancy:
Description: Instance tenancy behavior for this VPC
Type: String
Default: default
AllowedValues:
- default
- dedicated
pBastionSSHCIDR:
Type: String
Default: 0.0.0.0/0
Description: The CIDR Allowed SSH access to the bastion host
pBastionAmi:
Description: AMI to use for bastion host
Type: String
Default: ''
pEC2KeyPair:
Description: Name of existing EC2 key pair for production hosts
Type: String
Default: ''
pEnvironment:
Description: Environment (development, test, or production)
Type: String
Default: development
pSupportsNatGateway:
Description: Specifies whether this region supports NAT Gateway (this value is determined by the main stack if it is invoked from there)
Type: String
Default: true
pNatInstanceType:
Description: Instance type to use for the NAT intstance if the region does not support NAT Gateway (this value is determined by the main stack if it is invoked from there)
Type: String
Default: ''
pNatAmi:
Description: AMI to use for the NAT intstance if the region does not support NAT Gateway (this value is determined by the main stack if it is invoked from there)
Type: String
Default: ''
pFlowLogGroup:
Description: Log Group for capturing VPC Flow Logs
Type: String
Default: ''
QuickStartS3URL:
Description: Quick Start S3 URL prefix.
Default: https://s3.amazonaws.com
Type: String
QSS3BucketName:
AllowedPattern: ^[0-9a-zA-Z]+([0-9a-zA-Z\-\.]*[0-9a-zA-Z])*$
ConstraintDescription: Quick Start bucket name can include numbers, lowercase
letters, uppercase letters, periods (.), and hyphens (-). It cannot start or end with a hyphen
(-).
Default: quickstart-reference
Description: S3 bucket name for the Quick Start assets. Quick Start bucket name
can include numbers, lowercase letters, uppercase letters, periods (.), and hyphens (-).
It cannot start or end with a hyphen (-).
Type: String
QSS3KeyPrefix:
AllowedPattern: ^[0-9a-zA-Z-]+(/[0-9a-zA-Z-]+)*$
ConstraintDescription: Quick Start key prefix can include numbers, lowercase letters,
uppercase letters, hyphens (-), and forward slash (/). It cannot start or end
with forward slash (/) because they are automatically appended.
Default: quickstart-enterprise-accelerator-nist
Description: S3 key prefix for the Quick Start assets. Quick Start key prefix
can include numbers, lowercase letters, uppercase letters, hyphens (-), and
forward slash (/). It cannot start or end with forward slash (/) because they
are automatically appended.
Type: String
Conditions:
cCreateBastionHost: !Equals [ true, !Ref pCreateBastionHost ]
cCreatePeeringProduction: !Not [ !Equals [ '', !Ref pProductionVPC] ]
cNeedNatInstance: !Equals [ false, !Ref pSupportsNatGateway ]
cSupportsNatGateway: !Equals [ true, !Ref pSupportsNatGateway ]
cEnableFlowLogs: !Not [ !Equals [ !Ref pFlowLogGroup, '' ] ]
Resources:
rVPCManagement:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref pManagementCIDR
InstanceTenancy: !Ref pVPCTenancy
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Ref pManagementVPCName
rNatInstanceTemplate:
Type: AWS::CloudFormation::Stack
Condition: cNeedNatInstance
Properties:
TemplateURL: !Sub ${QuickStartS3URL}/${QSS3BucketName}/${QSS3KeyPrefix}/nat-instance.template
TimeoutInMinutes: 20
Parameters:
pDMZSubnetA: !Ref rManagementDMZSubnetA
pSecurityGroupSSHFromVpc: !Ref rSecurityGroupSSHFromMgmt
pSecurityGroupVpcNat: !Ref rSecurityGroupVpcNat
pNatInstanceType: !Ref pNatInstanceType
pNatAmi: !Ref pNatAmi
pEC2KeyPair: !Ref pEC2KeyPair
pVpcId: !Ref rVPCManagement
pVpcName: !Ref pManagementVPCName
pRouteTablePrivateA: !Ref rRouteTableMgmtPrivate
pRouteTablePrivateB: ''
pEipNatAllocationId: !GetAtt rEIPProdNAT.AllocationId
rSecurityGroupVpcNat:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow NAT from Management VPC
VpcId: !Ref rVPCManagement
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: !Ref pManagementCIDR
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !Ref pManagementCIDR
Tags:
- Key: Name
Value: sg-web-access-ports-from-production
- Key: Environment
Value: !Ref pEnvironment
rManagementDMZSubnetA:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref pManagementDMZSubnetACIDR
AvailabilityZone: !Ref pRegionAZ1Name
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management DMZ Subnet A
rManagementDMZSubnetB:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref pManagementDMZSubnetBCIDR
AvailabilityZone: !Ref pRegionAZ2Name
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management DMZ Subnet B
rManagementPrivateSubnetA:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref pManagementPrivateSubnetACIDR
AvailabilityZone: !Ref pRegionAZ1Name
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management Private Subnet A
rManagementPrivateSubnetB:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref pManagementPrivateSubnetBCIDR
AvailabilityZone: !Ref pRegionAZ2Name
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management Private Subnet B
rIGWManagement:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: igw-management
rRouteTableMgmtPrivate:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management Private Route
rRouteTableMgmtDMZ:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: Management DMZ Route
rRouteMgmtIGW:
DependsOn:
- rGWAttachmentMgmtIGW
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref rRouteTableMgmtDMZ
GatewayId: !Ref rIGWManagement
DestinationCidrBlock: 0.0.0.0/0
rRouteAssocMgmtDMZA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref rRouteTableMgmtDMZ
SubnetId: !Ref rManagementDMZSubnetA
rRouteAssocMgmtDMZB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref rRouteTableMgmtDMZ
SubnetId: !Ref rManagementDMZSubnetB
rRouteAssocMgmtPrivA:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref rRouteTableMgmtPrivate
SubnetId: !Ref rManagementPrivateSubnetA
rRouteAssocMgmtPrivB:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref rRouteTableMgmtPrivate
SubnetId: !Ref rManagementPrivateSubnetB
rENIProductionBastion:
Condition: cCreateBastionHost
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref rManagementDMZSubnetA
GroupSet:
- !Ref rSecurityGroupBastion
Description: Interface for Bastion device
Tags:
- Key: Network
Value: MgmtBastionDevice
rMgmtBastionInstance:
Type: AWS::EC2::Instance
Condition: cCreateBastionHost
Properties:
InstanceType: !Ref pBastionInstanceType
KeyName: !Ref pEC2KeyPairBastion
Tags:
- Key: Name
Value: Bastion Server
ImageId: !Ref pBastionAmi
NetworkInterfaces:
- NetworkInterfaceId: !Ref rENIProductionBastion
DeviceIndex: 0
UserData: !Base64 |
#!/bin/bash
yum update -y
rEIPProdBastion:
Type: AWS::EC2::EIP
Condition: cCreateBastionHost
Properties:
Domain: vpc
AssociaterEIPProdBastion:
Type: AWS::EC2::EIPAssociation
Condition: cCreateBastionHost
Properties:
AllocationId: !GetAtt rEIPProdBastion.AllocationId
NetworkInterfaceId: !Ref rENIProductionBastion
rEIPManagementNAT:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
rSecurityGroupSSHFromMgmt:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
VpcId: !Ref rVPCManagement
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref pManagementCIDR
Tags:
- Key: Name
Value: sg-ssh-access-from-management
- Key: Environment
Value: !Ref pEnvironment
rManagementNATInstanceInterface:
Type: AWS::EC2::NetworkInterface
Properties:
SubnetId: !Ref rManagementDMZSubnetA
GroupSet:
- !Ref rSecurityGroupSSHFromMgmt
- !Ref rSecurityGroupVpcNat
Description: Interface for Nat device
Tags:
- Key: Network
Value: rManagementNATInstanceInterface
AssociaterEIPManagementNAT:
Type: AWS::EC2::EIPAssociation
Properties:
AllocationId: !GetAtt rEIPManagementNAT.AllocationId
NetworkInterfaceId: !Ref rManagementNATInstanceInterface
rEIPProdNAT:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
rNATGateway:
Type: AWS::EC2::NatGateway
Condition: cSupportsNatGateway
DependsOn: rIGWManagement
Properties:
AllocationId: !GetAtt rEIPProdNAT.AllocationId
SubnetId: !Ref rManagementDMZSubnetA
rGWAttachmentMgmtIGW:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref rVPCManagement
InternetGatewayId: !Ref rIGWManagement
rSecurityGroupBastion:
Type: AWS::EC2::SecurityGroup
Condition: cCreateBastionHost
Properties:
GroupDescription: SG for Bastion Instances
VpcId: !Ref rVPCManagement
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref pBastionSSHCIDR
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 1
ToPort: 65535
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: sg-ssh-access-from-bastion
- Key: Environment
Value: !Ref pEnvironment
rPeeringConnectionProduction:
Type: AWS::EC2::VPCPeeringConnection
Condition: cCreatePeeringProduction
Properties:
PeerVpcId: !Ref pProductionVPC
VpcId: !Ref rVPCManagement
Tags:
- Key: Name
Value: vpc-peer-production-management
- Key: Environment
Value: !Ref pEnvironment
rRouteMgmtProdPrivate:
Condition: cCreatePeeringProduction
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref rRouteTableMgmtPrivate
VpcPeeringConnectionId: !Ref rPeeringConnectionProduction
DestinationCidrBlock: !Ref pProductionCIDR
rRouteMgmtNGW:
Condition: cSupportsNatGateway
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref rRouteTableMgmtPrivate
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref rNATGateway
rRouteProdMgmt:
Condition: cCreatePeeringProduction
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref pRouteTableProdPrivate
VpcPeeringConnectionId: !Ref rPeeringConnectionProduction
DestinationCidrBlock: !Ref pManagementCIDR
rRouteProdMgmtPublic:
Condition: cCreatePeeringProduction
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref pRouteTableProdPublic
VpcPeeringConnectionId: !Ref rPeeringConnectionProduction
DestinationCidrBlock: !Ref pManagementCIDR
rRouteMgmtProdDMZ:
Condition: cCreatePeeringProduction
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref rRouteTableMgmtDMZ
VpcPeeringConnectionId: !Ref rPeeringConnectionProduction
DestinationCidrBlock: !Ref pProductionCIDR
rManagementVpcFlowLogsServiceRole:
Condition: cEnableFlowLogs
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: AllowFlowLogs
Effect: Allow
Principal:
Service: vpc-flow-logs.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: cloudwatchlogsrole
PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogGroups
- logs:DescribeLogStreams
Effect: Allow
Resource: '*'
rManagementVpcFlowLog:
Condition: cEnableFlowLogs
Type: AWS::EC2::FlowLog
Properties:
DeliverLogsPermissionArn: !GetAtt rManagementVpcFlowLogsServiceRole.Arn
LogGroupName: !Ref pFlowLogGroup
ResourceId: !Ref rVPCManagement
ResourceType: VPC
TrafficType: ALL
rManagementVpcFlowLogStream:
Condition: cEnableFlowLogs
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref pFlowLogGroup
Outputs:
rVPCManagement:
Value: !Ref rVPCManagement
rBastionInstanceIP:
Condition: cCreateBastionHost
Value: !If [ cCreateBastionHost, !Ref rEIPProdBastion, '' ]
rManagementDMZSubnetA:
Value: !Ref rManagementDMZSubnetA
rManagementDMZSubnetB:
Value: !Ref rManagementDMZSubnetB
rManagementPrivateSubnetA:
Value: !Ref rManagementPrivateSubnetA
rManagementPrivateSubnetB:
Value: !Ref rManagementPrivateSubnetB
rRouteTableMgmtPrivate:
Value: !Ref rRouteTableMgmtPrivate
rRouteTableMgmtDMZ:
Value: !Ref rRouteTableMgmtDMZ
rSecurityGroupVpcNat:
Value: !Ref rSecurityGroupVpcNat
rEIPManagementNAT:
Value: !Ref rEIPProdNAT
rSecurityGroupSSHFromMgmt:
Value: !Ref rSecurityGroupSSHFromMgmt