-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ec2): internet gateway is created even if public subnets are reserved #28607
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
40ac987
fix(ec2): internet gateway is created even if public subnets are rese…
go-to-k 9bc57ad
integ test
go-to-k c0943af
change test name
go-to-k 5d098ea
change for determineNatGatewayCount
go-to-k ae7e200
change unit tests
go-to-k 1a421ec
Merge branch 'main' into ec2-vpc-reserved-ig
paulhcsun ad80267
Merge branch 'main' into ec2-vpc-reserved-ig
paulhcsun a601f70
Merge branch 'main' into ec2-vpc-reserved-ig
paulhcsun 12c82b6
Merge branch 'main' into ec2-vpc-reserved-ig
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -379,6 +379,26 @@ describe('vpc', () => { | |||
|
||||
}); | ||||
|
||||
test('with reserved public subnets, should not create the internet gateway', () => { | ||||
const stack = getTestStack(); | ||||
const vpc = new Vpc(stack, 'TheVPC', { | ||||
subnetConfiguration: [ | ||||
{ | ||||
subnetType: SubnetType.PRIVATE_ISOLATED, | ||||
name: 'isolated', | ||||
}, | ||||
{ | ||||
subnetType: SubnetType.PUBLIC, | ||||
name: 'public', | ||||
reserved: true, | ||||
}, | ||||
], | ||||
}); | ||||
Template.fromStack(stack).resourceCountIs('AWS::EC2::InternetGateway', 0); | ||||
Template.fromStack(stack).resourceCountIs('AWS::EC2::VPCGatewayAttachment', 0); | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
}); | ||||
|
||||
test('with subnets and reserved subnets defined, VPC subnet count should not contain reserved subnets ', () => { | ||||
const stack = getTestStack(); | ||||
new Vpc(stack, 'TheVPC', { | ||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly thought the following would be good here, but I'll leave it as is. (Because even as it is, the code after this will make a proper error if there is no
PUBLIC
and there isPRIVATE_WITH_EGRESS
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two implementations are different and
subnet => (subnet.subnetType === SubnetType.PUBLIC && !subnet.reserved)).length > 0;
would not allow the creation of internet or NAT gateways forPRIVATE_WITH_EGRESS
subnets (unless at least a public subnet is present).Can you please elaborate on why you considered making the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that trying to create Nat gateways with
PRIVATE_WITH_EGRESS
without a public subnet in the first place would result in an error.https://github.com/aws/aws-cdk/blob/v2.118.0/packages/aws-cdk-lib/aws-ec2/lib/vpc.ts#L2416-L2419
As for the Internet Gateway, I questioned whether there was a need to create it without a public subnet (like the following code). However, since it is not good to carelessly change the behavior, I left it as it was, just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification.
Yeah, I'd just leave it as is unless we have a specific reason to change it to avoid potential errors with existing deployments.