Skip to content

Commit 5598396

Browse files
committed
Add CloudFormation template
1 parent fdcf2e4 commit 5598396

File tree

1 file changed

+236
-0
lines changed

1 file changed

+236
-0
lines changed
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
Description:
2+
This template deploys a VPC, with a pair of public and private subnets spread
3+
across two Availability Zones. It deploys an Internet Gateway, with a default
4+
route on the public subnets. It deploys a pair of NAT Gateways (one in each AZ),
5+
and default routes for them in the private subnets.
6+
7+
Parameters:
8+
EnvironmentName:
9+
Description: An environment name that will be prefixed to resource names
10+
Type: String
11+
12+
VpcCIDR:
13+
Description: Please enter the IP range (CIDR notation) for this VPC
14+
Type: String
15+
Default: 10.192.0.0/16
16+
17+
PublicSubnet1CIDR:
18+
Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
19+
Type: String
20+
Default: 10.192.10.0/24
21+
22+
PublicSubnet2CIDR:
23+
Description: Please enter the IP range (CIDR notation) for the public subnet in the second Availability Zone
24+
Type: String
25+
Default: 10.192.11.0/24
26+
27+
PrivateSubnet1CIDR:
28+
Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone
29+
Type: String
30+
Default: 10.192.20.0/24
31+
32+
PrivateSubnet2CIDR:
33+
Description: Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
34+
Type: String
35+
Default: 10.192.21.0/24
36+
37+
Resources:
38+
VPC:
39+
Type: AWS::EC2::VPC
40+
Properties:
41+
CidrBlock: !Ref VpcCIDR
42+
Tags:
43+
- Key: Name
44+
Value: !Ref EnvironmentName
45+
46+
InternetGateway:
47+
Type: AWS::EC2::InternetGateway
48+
Properties:
49+
Tags:
50+
- Key: Name
51+
Value: !Ref EnvironmentName
52+
53+
InternetGatewayAttachment:
54+
Type: AWS::EC2::VPCGatewayAttachment
55+
Properties:
56+
InternetGatewayId: !Ref InternetGateway
57+
VpcId: !Ref VPC
58+
59+
PublicSubnet1:
60+
Type: AWS::EC2::Subnet
61+
Properties:
62+
VpcId: !Ref VPC
63+
AvailabilityZone: !Select [ 0, !GetAZs '' ]
64+
CidrBlock: !Ref PublicSubnet1CIDR
65+
MapPublicIpOnLaunch: true
66+
Tags:
67+
- Key: Name
68+
Value: !Sub ${EnvironmentName} Public Subnet (AZ1)
69+
70+
PublicSubnet2:
71+
Type: AWS::EC2::Subnet
72+
Properties:
73+
VpcId: !Ref VPC
74+
AvailabilityZone: !Select [ 1, !GetAZs '' ]
75+
CidrBlock: !Ref PublicSubnet2CIDR
76+
MapPublicIpOnLaunch: true
77+
Tags:
78+
- Key: Name
79+
Value: !Sub ${EnvironmentName} Public Subnet (AZ2)
80+
81+
PrivateSubnet1:
82+
Type: AWS::EC2::Subnet
83+
Properties:
84+
VpcId: !Ref VPC
85+
AvailabilityZone: !Select [ 0, !GetAZs '' ]
86+
CidrBlock: !Ref PrivateSubnet1CIDR
87+
MapPublicIpOnLaunch: false
88+
Tags:
89+
- Key: Name
90+
Value: !Sub ${EnvironmentName} Private Subnet (AZ1)
91+
92+
PrivateSubnet2:
93+
Type: AWS::EC2::Subnet
94+
Properties:
95+
VpcId: !Ref VPC
96+
AvailabilityZone: !Select [ 1, !GetAZs '' ]
97+
CidrBlock: !Ref PrivateSubnet2CIDR
98+
MapPublicIpOnLaunch: false
99+
Tags:
100+
- Key: Name
101+
Value: !Sub ${EnvironmentName} Private Subnet (AZ2)
102+
103+
NatGateway1EIP:
104+
Type: AWS::EC2::EIP
105+
DependsOn: InternetGatewayAttachment
106+
Properties:
107+
Domain: vpc
108+
109+
NatGateway2EIP:
110+
Type: AWS::EC2::EIP
111+
DependsOn: InternetGatewayAttachment
112+
Properties:
113+
Domain: vpc
114+
115+
NatGateway1:
116+
Type: AWS::EC2::NatGateway
117+
Properties:
118+
AllocationId: !GetAtt NatGateway1EIP.AllocationId
119+
SubnetId: !Ref PublicSubnet1
120+
121+
NatGateway2:
122+
Type: AWS::EC2::NatGateway
123+
Properties:
124+
AllocationId: !GetAtt NatGateway2EIP.AllocationId
125+
SubnetId: !Ref PublicSubnet2
126+
127+
PublicRouteTable:
128+
Type: AWS::EC2::RouteTable
129+
Properties:
130+
VpcId: !Ref VPC
131+
Tags:
132+
- Key: Name
133+
Value: !Sub ${EnvironmentName} Public Routes
134+
135+
DefaultPublicRoute:
136+
Type: AWS::EC2::Route
137+
DependsOn: InternetGatewayAttachment
138+
Properties:
139+
RouteTableId: !Ref PublicRouteTable
140+
DestinationCidrBlock: 0.0.0.0/0
141+
GatewayId: !Ref InternetGateway
142+
143+
PublicSubnet1RouteTableAssociation:
144+
Type: AWS::EC2::SubnetRouteTableAssociation
145+
Properties:
146+
RouteTableId: !Ref PublicRouteTable
147+
SubnetId: !Ref PublicSubnet1
148+
149+
PublicSubnet2RouteTableAssociation:
150+
Type: AWS::EC2::SubnetRouteTableAssociation
151+
Properties:
152+
RouteTableId: !Ref PublicRouteTable
153+
SubnetId: !Ref PublicSubnet2
154+
155+
156+
PrivateRouteTable1:
157+
Type: AWS::EC2::RouteTable
158+
Properties:
159+
VpcId: !Ref VPC
160+
Tags:
161+
- Key: Name
162+
Value: !Sub ${EnvironmentName} Private Routes (AZ1)
163+
164+
DefaultPrivateRoute1:
165+
Type: AWS::EC2::Route
166+
Properties:
167+
RouteTableId: !Ref PrivateRouteTable1
168+
DestinationCidrBlock: 0.0.0.0/0
169+
NatGatewayId: !Ref NatGateway1
170+
171+
PrivateSubnet1RouteTableAssociation:
172+
Type: AWS::EC2::SubnetRouteTableAssociation
173+
Properties:
174+
RouteTableId: !Ref PrivateRouteTable1
175+
SubnetId: !Ref PrivateSubnet1
176+
177+
PrivateRouteTable2:
178+
Type: AWS::EC2::RouteTable
179+
Properties:
180+
VpcId: !Ref VPC
181+
Tags:
182+
- Key: Name
183+
Value: !Sub ${EnvironmentName} Private Routes (AZ2)
184+
185+
DefaultPrivateRoute2:
186+
Type: AWS::EC2::Route
187+
Properties:
188+
RouteTableId: !Ref PrivateRouteTable2
189+
DestinationCidrBlock: 0.0.0.0/0
190+
NatGatewayId: !Ref NatGateway2
191+
192+
PrivateSubnet2RouteTableAssociation:
193+
Type: AWS::EC2::SubnetRouteTableAssociation
194+
Properties:
195+
RouteTableId: !Ref PrivateRouteTable2
196+
SubnetId: !Ref PrivateSubnet2
197+
198+
NoIngressSecurityGroup:
199+
Type: AWS::EC2::SecurityGroup
200+
Properties:
201+
GroupName: "no-ingress-sg"
202+
GroupDescription: "Security group with no ingress rule"
203+
VpcId: !Ref VPC
204+
205+
Outputs:
206+
VPC:
207+
Description: A reference to the created VPC
208+
Value: !Ref VPC
209+
210+
PublicSubnets:
211+
Description: A list of the public subnets
212+
Value: !Join [ ",", [ !Ref PublicSubnet1, !Ref PublicSubnet2 ]]
213+
214+
PrivateSubnets:
215+
Description: A list of the private subnets
216+
Value: !Join [ ",", [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ]]
217+
218+
PublicSubnet1:
219+
Description: A reference to the public subnet in the 1st Availability Zone
220+
Value: !Ref PublicSubnet1
221+
222+
PublicSubnet2:
223+
Description: A reference to the public subnet in the 2nd Availability Zone
224+
Value: !Ref PublicSubnet2
225+
226+
PrivateSubnet1:
227+
Description: A reference to the private subnet in the 1st Availability Zone
228+
Value: !Ref PrivateSubnet1
229+
230+
PrivateSubnet2:
231+
Description: A reference to the private subnet in the 2nd Availability Zone
232+
Value: !Ref PrivateSubnet2
233+
234+
NoIngressSecurityGroup:
235+
Description: Security group with no ingress rule
236+
Value: !Ref NoIngressSecurityGroup

0 commit comments

Comments
 (0)