forked from w3kp/vpc-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc-fullstack-01.yaml
More file actions
208 lines (197 loc) · 7.19 KB
/
vpc-fullstack-01.yaml
File metadata and controls
208 lines (197 loc) · 7.19 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
# Network Design Patterns
# 1 tier, single subnet, public
# 1 tier, single subnet, private, 1 nat
# 2 tier, two subnets, public + private, 1 nat
# 2 tier, two subnets, public + private, 2 nat
# 3 tier, three subnets, public + private + database, 1 nat
# 3 tier, three subnets, public + private + database, 2 nat
AWSTemplateFormatVersion: 2010-09-09
Description: Creates VPC, Subnets, Internet Gateway, Nat Gateways, RouteTables, Security Groups and more.
Metadata:
Authors:
Description: Paul Bartocillo (pebartocillo@apper.ph) - Apper Digital Inc.
License:
Description:
"Copyright 2020 Amazon.com, Inc. and its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0"
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Amazon VPC Parameters
Parameters:
- EnvironmentName
- NetworkDesignPatterns
- VpcCidr
- SubnetsCidrBlock
ParameterLabels:
EnvironmentName:
default: Environment Name
NetworkDesignPatterns:
default: Network Design Patterns
VpcCidr:
default: VPC CIDR Block
SubnetsCidrBlock:
default: Subnets CIDR Blocks
Parameters:
EnvironmentName:
Description: The name of environment for the current stack (e.g. dev, test, staging, beta, production).
Type: String
NetworkDesignPatterns:
Description: The design pattern of the current vpc network architecture based from industry standards and cost tradeoffs
Type: String
AllowedValues:
- "1 tier | 1 subnet | public"
- "1 tier | 2 subnets | public"
- "2 tier | 2 subnets public | 2 subnets private | 1 nat"
- "2 tier | 2 subnets public | 2 subnets private | 2 nat"
- "3 tier | 2 subnets public | 2 subnets private | 2 subnets database | 1 nat"
- "3 tier | 2 subnets public | 2 subnets private | 2 subnets database | 2 nat"
Default: "1 tier | 1 subnet | public"
VpcCidr:
AllowedPattern: "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/(1[6-9]|2[0-8]))$"
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/16
Description: CIDR block for the VPC
Type: String
SubnetsCidrBlock:
Description: |
Comma-delimited list of CIDR blocks for subnets located in AZ's within the current AWS Regions (e.g. 10.0.1.0/24, 10.0.2.0/24, 10.0.3.0/24).
Note: The logical order is preserved and must be greater than or equal to the number of subnet selected in the network design pattern field.
Type: CommaDelimitedList
Default: "10.0.1.0/24, 10.0.2.0/24, 10.0.3.0/24"
Conditions:
# parameter conditionals
1Tier1SubPublic: !Equals [!Ref NetworkDesignPatterns, "1 tier | 1 subnet | public"]
1Tier2SubPublic: !Equals [!Ref NetworkDesignPatterns, "1 tier | 2 subnets | public"]
2Tier2SubPublicPrivate1Nat: !Equals [!Ref NetworkDesignPatterns, "2 tier | 2 subnets public | 2 subnets private | 1 nat"]
2Tier2SubPublicPrivate2Nat: !Equals [!Ref NetworkDesignPatterns, "2 tier | 2 subnets public | 2 subnets private | 2 nat"]
3Tier2SubPublicPrivateDatabase1Nat: !Equals [!Ref NetworkDesignPatterns, "3 tier | 2 subnets public | 2 subnets private | 2 subnets database | 1 nat"]
3Tier2SubPublicPrivateDatabase2Nat: !Equals [!Ref NetworkDesignPatterns, "3 tier | 2 subnets public | 2 subnets private | 2 subnets database | 2 nat"]
# template conditionals
1Subnet: !Or
- !Condition 1Tier1SubPublic
- !Condition 1Tier2SubPublic
- !Condition 2Tier2SubPublicPrivate1Nat
- !Condition 2Tier2SubPublicPrivate2Nat
- !Condition 3Tier2SubPublicPrivateDatabase1Nat
- !Condition 3Tier2SubPublicPrivateDatabase2Nat
2Subnet: !Or
- !Condition 1Tier2SubPublic
- !Condition 2Tier2SubPublicPrivate1Nat
- !Condition 2Tier2SubPublicPrivate2Nat
- !Condition 3Tier2SubPublicPrivateDatabase1Nat
- !Condition 3Tier2SubPublicPrivateDatabase2Nat
1Nat: !Or
- !Condition 2Tier2SubPublicPrivate1Nat
- !Condition 3Tier2SubPublicPrivateDatabase1Nat
2Nat: !Or
- !Condition 2Tier2SubPublicPrivate2Nat
- !Condition 3Tier2SubPublicPrivateDatabase2Nat
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCidr
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: !Sub "${EnvironmentName}-vpc-${AWS::StackName}"
- Key: Environment
Value: !Ref EnvironmentName
- Key: Type
Value: "Managed by AWS Cloudformation"
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub "${EnvironmentName}-igw-${AWS::StackName}"
- Key: Environment
Value: !Ref EnvironmentName
- Key: Type
Value: "Managed by AWS Cloudformation"
AttachInternetGateway:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref Vpc
# VPC ROUTES
PublicRoute:
Type: AWS::EC2::Route
DependsOn: AttachInternetGateway
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
# SUBNETS
PublicAZASubnet:
Condition: 1Subnet
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
AvailabilityZone: !Select [0, Fn::GetAZs: !Ref "AWS::Region"]
CidrBlock: !Select [0, !Ref SubnetsCidrBlock]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub "${EnvironmentName}-public-sub1-${AWS::StackName}"
- Key: Environment
Value: !Ref EnvironmentName
- Key: Type
Value: "Managed by AWS Cloudformation"
PublicAZBSubnet:
Condition: 2Subnet
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
AvailabilityZone: !Select [1, Fn::GetAZs: !Ref "AWS::Region"]
CidrBlock: !Select [1, !Ref SubnetsCidrBlock]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub "${EnvironmentName}-public-sub2-${AWS::StackName}"
- Key: Environment
Value: !Ref EnvironmentName
- Key: Type
Value: "Managed by AWS Cloudformation"
# ROUTE TABLE
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref Vpc
Tags:
- Key: Name
Value: !Sub "${EnvironmentName}-public-rt-${AWS::StackName}"
- Key: Environment
Value: !Ref EnvironmentName
- Key: Type
Value: "Managed by AWS Cloudformation"
# ROUTE ASSOC
PublicRouteTableAssociation1:
Condition: 1Subnet
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicAZASubnet
RouteTableId: !Ref PublicRouteTable
PublicRouteTableAssociation2:
Condition: 2Subnet
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicAZBSubnet
RouteTableId: !Ref PublicRouteTable
Outputs:
Vpc:
Value: !Ref Vpc
VpcCidr:
Value: !Ref VpcCidr
SubnetsCidrBlock:
Value: !Join
- ","
- !Ref SubnetsCidrBlock
PublicAZASubnet:
Condition: 1Subnet
Value: !Ref PublicAZASubnet
PublicAZBSubnet:
Condition: 2Subnet
Value: !Ref PublicAZBSubnet