-
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
feat(vpc): additional validation around Subnet Types #4668
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -164,8 +164,8 @@ export = { | |
subnetConfiguration: [ | ||
{ | ||
cidrMask: 24, | ||
subnetType: SubnetType.PRIVATE, | ||
name: 'Private', | ||
subnetType: SubnetType.PUBLIC, | ||
name: 'Public', | ||
}, | ||
{ | ||
cidrMask: 24, | ||
|
@@ -192,7 +192,7 @@ export = { | |
{ | ||
cidrMask: 24, | ||
name: 'ingress', | ||
subnetType: SubnetType.PRIVATE, | ||
subnetType: SubnetType.PUBLIC, | ||
}, | ||
{ | ||
cidrMask: 24, | ||
|
@@ -415,6 +415,18 @@ export = { | |
} | ||
test.done(); | ||
}, | ||
|
||
'natGateways = 0 requires there to be no PRIVATE subnets'(test: Test) { | ||
const stack = getTestStack(); | ||
test.throws(() => { | ||
new Vpc(stack, 'VPC', { | ||
natGateways: 0, | ||
}); | ||
}, /make sure you don't configure any PRIVATE subnets/); | ||
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. Perhaps provide the rationale for this in the error message or an accompanying link to an issue or doc |
||
test.done(); | ||
|
||
}, | ||
|
||
'with mis-matched nat and subnet configs it throws'(test: Test) { | ||
const stack = getTestStack(); | ||
test.throws(() => new Vpc(stack, 'VPC', { | ||
|
@@ -480,7 +492,7 @@ export = { | |
const stack = getTestStack(); | ||
new Vpc(stack, 'VPC', { | ||
subnetConfiguration: [ | ||
{ subnetType: SubnetType.PRIVATE, name: 'Private' }, | ||
{ subnetType: SubnetType.PUBLIC, name: 'Public' }, | ||
{ subnetType: SubnetType.ISOLATED, name: 'Isolated' }, | ||
], | ||
vpnGateway: true, | ||
|
@@ -514,6 +526,7 @@ export = { | |
const stack = getTestStack(); | ||
new Vpc(stack, 'VPC', { | ||
subnetConfiguration: [ | ||
{ subnetType: SubnetType.PUBLIC, name: 'Public' }, | ||
{ subnetType: SubnetType.PRIVATE, name: 'Private' }, | ||
{ subnetType: SubnetType.ISOLATED, name: 'Isolated' }, | ||
], | ||
|
@@ -749,7 +762,7 @@ export = { | |
const stack = getTestStack(); | ||
const vpc = new Vpc(stack, 'VPC', { | ||
subnetConfiguration: [ | ||
{ subnetType: SubnetType.PRIVATE, name: 'Private' }, | ||
{ subnetType: SubnetType.PUBLIC, name: 'Public' }, | ||
{ subnetType: SubnetType.ISOLATED, name: 'Isolated' }, | ||
] | ||
}); | ||
|
@@ -768,6 +781,7 @@ export = { | |
const stack = getTestStack(); | ||
const vpc = new Vpc(stack, 'VPC', { | ||
subnetConfiguration: [ | ||
{ subnetType: SubnetType.PUBLIC, name: 'BlaBla' }, | ||
{ subnetType: SubnetType.PRIVATE, name: 'DontTalkToMe' }, | ||
{ subnetType: SubnetType.ISOLATED, name: 'DontTalkAtAll' }, | ||
] | ||
|
@@ -786,6 +800,7 @@ export = { | |
const stack = getTestStack(); | ||
const vpc = new Vpc(stack, 'VPC', { | ||
subnetConfiguration: [ | ||
{ subnetType: SubnetType.PUBLIC, name: 'BlaBla' }, | ||
{ subnetType: SubnetType.PRIVATE, name: 'DontTalkToMe' }, | ||
{ subnetType: SubnetType.ISOLATED, name: 'DontTalkAtAll' }, | ||
] | ||
|
@@ -799,7 +814,25 @@ export = { | |
test.done(); | ||
}, | ||
|
||
'selecting default subnets in a VPC with only public subnets throws an error'(test: Test) { | ||
'selecting default subnets in a VPC with only isolated subnets returns the isolateds'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const vpc = Vpc.fromVpcAttributes(stack, 'VPC', { | ||
vpcId: 'vpc-1234', | ||
availabilityZones: ['dummy1a', 'dummy1b', 'dummy1c'], | ||
isolatedSubnetIds: ['iso-1', 'iso-2', 'iso-3'], | ||
isolatedSubnetRouteTableIds: ['rt-1', 'rt-2', 'rt-3'], | ||
}); | ||
|
||
// WHEN | ||
const subnets = vpc.selectSubnets(); | ||
|
||
// THEN | ||
test.deepEqual(subnets.subnetIds, ['iso-1', 'iso-2', 'iso-3']); | ||
test.done(); | ||
}, | ||
|
||
'selecting default subnets in a VPC with only public subnets returns the publics'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const vpc = Vpc.fromVpcAttributes(stack, 'VPC', { | ||
|
@@ -809,10 +842,11 @@ export = { | |
publicSubnetRouteTableIds: ['rt-1', 'rt-2', 'rt-3'], | ||
}); | ||
|
||
test.throws(() => { | ||
vpc.selectSubnets(); | ||
}, /There are no 'Private' subnet groups in this VPC. Available types: Public/); | ||
// WHEN | ||
const subnets = vpc.selectSubnets(); | ||
|
||
// THEN | ||
test.deepEqual(subnets.subnetIds, ['pub-1', 'pub-2', 'pub-3']); | ||
test.done(); | ||
}, | ||
|
||
|
@@ -834,6 +868,7 @@ export = { | |
const vpc = new Vpc(stack, 'VpcNetwork', { | ||
maxAzs: 1, | ||
subnetConfiguration: [ | ||
{name: 'lb', subnetType: SubnetType.PUBLIC }, | ||
{name: 'app', subnetType: SubnetType.PRIVATE }, | ||
{name: 'db', subnetType: SubnetType.PRIVATE }, | ||
] | ||
|
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'm not sure this description of
@default
is super clear...ISOLATED or PUBLIC
? I don't think this is a valid value... Do you mean whichever value resolves to a subnet first in that order?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 do mean that. I can come up with a description of that behavior that is super technically correct ("The first one out of PRIVATE, ISOLATED, PUBLIC that has subnets of that type configured"), but not one that's easy to read.
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.
Yes, @rix0rrr I like you proposed change (and the value should be
-
). It should be something like: