Skip to content

Commit 985c7e4

Browse files
authored
fix(ec2): internet gateway is created even if public subnets are reserved (#28607)
This PR fixes that Internet Gateway will be created even if (all) public subnets are reserved. The `reserved` option is for not actually creating subnet resources. So IGW should not be created if all public subnets are reserved, because there is no public subnets in the VPC. It would be appropriate to consider the `reserved` option since [we originally did not want to create an IGW if there was no public subnets](https://github.com/aws/aws-cdk/blob/v2.118.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L1493-L1497). Also, if this bug is not fixed, it will go to the [code where the NatGateway is created](https://github.com/aws/aws-cdk/blob/v2.118.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L1513-L1517) without public subnets. (This will be stopped with another error, but...) Closes #28593. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 92a31fa commit 985c7e4

File tree

13 files changed

+1187
-2
lines changed

13 files changed

+1187
-2
lines changed

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/asset.4554b47be6f57b68c6c7a7391dcc73894866d2377fe174883351e7639097f292/__entrypoint__.js

+147
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/asset.4554b47be6f57b68c6c7a7391dcc73894866d2377fe174883351e7639097f292/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/aws-cdk-ec2-vpc-reserved-public-subnet.assets.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
{
2+
"Resources": {
3+
"VPCB9E5F0B4": {
4+
"Type": "AWS::EC2::VPC",
5+
"Properties": {
6+
"CidrBlock": "10.0.0.0/16",
7+
"EnableDnsHostnames": true,
8+
"EnableDnsSupport": true,
9+
"InstanceTenancy": "default",
10+
"Tags": [
11+
{
12+
"Key": "Name",
13+
"Value": "aws-cdk-ec2-vpc-reserved-public-subnet/VPC"
14+
}
15+
]
16+
}
17+
},
18+
"VPCisolatedSubnet1Subnet84AF7038": {
19+
"Type": "AWS::EC2::Subnet",
20+
"Properties": {
21+
"AvailabilityZone": {
22+
"Fn::Select": [
23+
0,
24+
{
25+
"Fn::GetAZs": ""
26+
}
27+
]
28+
},
29+
"CidrBlock": "10.0.128.0/18",
30+
"MapPublicIpOnLaunch": false,
31+
"Tags": [
32+
{
33+
"Key": "aws-cdk:subnet-name",
34+
"Value": "isolated"
35+
},
36+
{
37+
"Key": "aws-cdk:subnet-type",
38+
"Value": "Isolated"
39+
},
40+
{
41+
"Key": "Name",
42+
"Value": "aws-cdk-ec2-vpc-reserved-public-subnet/VPC/isolatedSubnet1"
43+
}
44+
],
45+
"VpcId": {
46+
"Ref": "VPCB9E5F0B4"
47+
}
48+
}
49+
},
50+
"VPCisolatedSubnet1RouteTable2BB88525": {
51+
"Type": "AWS::EC2::RouteTable",
52+
"Properties": {
53+
"Tags": [
54+
{
55+
"Key": "Name",
56+
"Value": "aws-cdk-ec2-vpc-reserved-public-subnet/VPC/isolatedSubnet1"
57+
}
58+
],
59+
"VpcId": {
60+
"Ref": "VPCB9E5F0B4"
61+
}
62+
}
63+
},
64+
"VPCisolatedSubnet1RouteTableAssociation2886DD39": {
65+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
66+
"Properties": {
67+
"RouteTableId": {
68+
"Ref": "VPCisolatedSubnet1RouteTable2BB88525"
69+
},
70+
"SubnetId": {
71+
"Ref": "VPCisolatedSubnet1Subnet84AF7038"
72+
}
73+
}
74+
},
75+
"VPCisolatedSubnet2Subnet8AE9E765": {
76+
"Type": "AWS::EC2::Subnet",
77+
"Properties": {
78+
"AvailabilityZone": {
79+
"Fn::Select": [
80+
1,
81+
{
82+
"Fn::GetAZs": ""
83+
}
84+
]
85+
},
86+
"CidrBlock": "10.0.192.0/18",
87+
"MapPublicIpOnLaunch": false,
88+
"Tags": [
89+
{
90+
"Key": "aws-cdk:subnet-name",
91+
"Value": "isolated"
92+
},
93+
{
94+
"Key": "aws-cdk:subnet-type",
95+
"Value": "Isolated"
96+
},
97+
{
98+
"Key": "Name",
99+
"Value": "aws-cdk-ec2-vpc-reserved-public-subnet/VPC/isolatedSubnet2"
100+
}
101+
],
102+
"VpcId": {
103+
"Ref": "VPCB9E5F0B4"
104+
}
105+
}
106+
},
107+
"VPCisolatedSubnet2RouteTable1EDFC77F": {
108+
"Type": "AWS::EC2::RouteTable",
109+
"Properties": {
110+
"Tags": [
111+
{
112+
"Key": "Name",
113+
"Value": "aws-cdk-ec2-vpc-reserved-public-subnet/VPC/isolatedSubnet2"
114+
}
115+
],
116+
"VpcId": {
117+
"Ref": "VPCB9E5F0B4"
118+
}
119+
}
120+
},
121+
"VPCisolatedSubnet2RouteTableAssociation8A6ECC3C": {
122+
"Type": "AWS::EC2::SubnetRouteTableAssociation",
123+
"Properties": {
124+
"RouteTableId": {
125+
"Ref": "VPCisolatedSubnet2RouteTable1EDFC77F"
126+
},
127+
"SubnetId": {
128+
"Ref": "VPCisolatedSubnet2Subnet8AE9E765"
129+
}
130+
}
131+
},
132+
"VPCRestrictDefaultSecurityGroupCustomResource59474679": {
133+
"Type": "Custom::VpcRestrictDefaultSG",
134+
"Properties": {
135+
"ServiceToken": {
136+
"Fn::GetAtt": [
137+
"CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E",
138+
"Arn"
139+
]
140+
},
141+
"DefaultSecurityGroupId": {
142+
"Fn::GetAtt": [
143+
"VPCB9E5F0B4",
144+
"DefaultSecurityGroup"
145+
]
146+
},
147+
"Account": {
148+
"Ref": "AWS::AccountId"
149+
}
150+
},
151+
"UpdateReplacePolicy": "Delete",
152+
"DeletionPolicy": "Delete"
153+
},
154+
"CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0": {
155+
"Type": "AWS::IAM::Role",
156+
"Properties": {
157+
"AssumeRolePolicyDocument": {
158+
"Version": "2012-10-17",
159+
"Statement": [
160+
{
161+
"Action": "sts:AssumeRole",
162+
"Effect": "Allow",
163+
"Principal": {
164+
"Service": "lambda.amazonaws.com"
165+
}
166+
}
167+
]
168+
},
169+
"ManagedPolicyArns": [
170+
{
171+
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
172+
}
173+
],
174+
"Policies": [
175+
{
176+
"PolicyName": "Inline",
177+
"PolicyDocument": {
178+
"Version": "2012-10-17",
179+
"Statement": [
180+
{
181+
"Effect": "Allow",
182+
"Action": [
183+
"ec2:AuthorizeSecurityGroupIngress",
184+
"ec2:AuthorizeSecurityGroupEgress",
185+
"ec2:RevokeSecurityGroupIngress",
186+
"ec2:RevokeSecurityGroupEgress"
187+
],
188+
"Resource": [
189+
{
190+
"Fn::Join": [
191+
"",
192+
[
193+
"arn:",
194+
{
195+
"Ref": "AWS::Partition"
196+
},
197+
":ec2:",
198+
{
199+
"Ref": "AWS::Region"
200+
},
201+
":",
202+
{
203+
"Ref": "AWS::AccountId"
204+
},
205+
":security-group/",
206+
{
207+
"Fn::GetAtt": [
208+
"VPCB9E5F0B4",
209+
"DefaultSecurityGroup"
210+
]
211+
}
212+
]
213+
]
214+
}
215+
]
216+
}
217+
]
218+
}
219+
}
220+
]
221+
}
222+
},
223+
"CustomVpcRestrictDefaultSGCustomResourceProviderHandlerDC833E5E": {
224+
"Type": "AWS::Lambda::Function",
225+
"Properties": {
226+
"Code": {
227+
"S3Bucket": {
228+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
229+
},
230+
"S3Key": "4554b47be6f57b68c6c7a7391dcc73894866d2377fe174883351e7639097f292.zip"
231+
},
232+
"Timeout": 900,
233+
"MemorySize": 128,
234+
"Handler": "__entrypoint__.handler",
235+
"Role": {
236+
"Fn::GetAtt": [
237+
"CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0",
238+
"Arn"
239+
]
240+
},
241+
"Runtime": "nodejs18.x",
242+
"Description": "Lambda function for removing all inbound/outbound rules from the VPC default security group"
243+
},
244+
"DependsOn": [
245+
"CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0"
246+
]
247+
}
248+
},
249+
"Parameters": {
250+
"BootstrapVersion": {
251+
"Type": "AWS::SSM::Parameter::Value<String>",
252+
"Default": "/cdk-bootstrap/hnb659fds/version",
253+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
254+
}
255+
},
256+
"Rules": {
257+
"CheckBootstrapVersion": {
258+
"Assertions": [
259+
{
260+
"Assert": {
261+
"Fn::Not": [
262+
{
263+
"Fn::Contains": [
264+
[
265+
"1",
266+
"2",
267+
"3",
268+
"4",
269+
"5"
270+
],
271+
{
272+
"Ref": "BootstrapVersion"
273+
}
274+
]
275+
}
276+
]
277+
},
278+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
279+
}
280+
]
281+
}
282+
}
283+
}

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/integawscdkec2vpcreservedpublicsubnetDefaultTestDeployAssert469B3DFB.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.reserved-public-subnet.js.snapshot/integawscdkec2vpcreservedpublicsubnetDefaultTestDeployAssert469B3DFB.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)