-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(BREAKING) Enhancement - Custom VPC Subnets #250
Merged
Merged
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
28aea13
initial network builder design
2beb4a7
fixing tabs == 4 spaces in network-util.ts
2a172ed
moving to `get` methods for subnets, adding additional comment detail
9da7a2f
moving network-util vaildIp func to filter instead of reduce for read…
moofish32 55e3666
renaming of VpcSubnetBuilderProps to SubnetConfiguration; doc updates…
moofish32 a2b527d
removing custom error classes and asserting on regex message
moofish32 c9d4f39
removing more bad uses of reduce
moofish32 af75c41
network-utils doc improvements
moofish32 88a6d94
refactor complete snapping a line to debug
moofish32 9ac38f4
adding error for too many AZs requested
moofish32 60ef32d
additional comments for CIDR math and odd behaviors
moofish32 0f0079a
integ test can run but we are breaking existing here
moofish32 abd5086
making default vpc backwards compatible
moofish32 6dabebe
fixing linter errors
moofish32 7be9cc5
refactoring to keep backwards compatibility with vpc subnet generatio…
moofish32 2d1bb07
Merge remote-tracking branch 'origin/master' into f-improve-vpc-network
moofish32 1ef7db6
fixing imports removed incorrectly on conflict resolution
moofish32 06350b4
removed numazs
moofish32 455d9ef
fixing private subnet routes in default
moofish32 701858c
refactor to remove SubnetConfigFinalized
moofish32 5ecb64a
updating to support maxNatGateways
moofish32 a5ce5d9
updates for integ tests for rds and vpc
moofish32 2fbb213
fixing route53
moofish32 1777874
updating Changelog, README, and comments; reordered SubnetType to be …
moofish32 9d8067f
minor README in ec2 update
moofish32 d639de4
changes from the readme (impact to vpc.ts because the rename of the s…
moofish32 f2d4571
updating to fix `||` idiom; updating Changelog to explain breaking
moofish32 5c1bc5d
addressing code comments and tests for natGateway default behavior
moofish32 0864bb8
addressing comments for maxNatGateway -> natGateways, removing mapPub…
moofish32 776f1e0
refactoring cidrblock and network builder for number centric ip manag…
moofish32 82246ae
refactoring CidrBlock for constructor overloading, renaming nextIp ot…
moofish32 864a341
a couple of comment clarifications and making the CidrBlock construct…
moofish32 9722cdc
missed one README typo
moofish32 bba5e67
final README (ec2) correction to create Advanced Subnet Configuration
moofish32 c2baa77
Merge branch 'master' into f-improve-vpc-network
moofish32 31057b2
minor tweaks for renames from master merge
moofish32 f3f5428
README modification to match `import ec2 = require('@aws-cdk/aws-ec2')`
moofish32 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 |
---|---|---|
|
@@ -25,6 +25,151 @@ into all private subnets, and provide a parameter called `vpcPlacement` to | |
allow you to override the placement. [Read more about | ||
subnets](https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html). | ||
|
||
If you require the ability to configure subnets the `VpcNetwork` can be | ||
customized with `SubnetConfiguration` array. This is best explained by an | ||
example: | ||
|
||
```ts | ||
import { VpcNetwork } from '@aws-cdk/ec2'; | ||
|
||
new VpcNetwork(stack, 'TheVPC', { | ||
cidr: '10.0.0.0/21', | ||
subnetConfiguration: [ | ||
{ | ||
cidrMask: 24, | ||
name: 'Ingress', | ||
subnetType: SubnetType.Public, | ||
natGateway: true, | ||
}, | ||
{ | ||
cidrMask: 24, | ||
name: 'Application', | ||
subnetType: SubnetType.Private, | ||
}, | ||
{ | ||
cidrMask: 28, | ||
name: 'Database', | ||
subnetType: SubnetType.Isolated, | ||
} | ||
], | ||
}); | ||
``` | ||
|
||
The example above is one possible configuration, but the user can use the | ||
constructs above to implement many other network configurations. | ||
|
||
The `VpcNetwork` from the above configuration in a Region with three | ||
availability zones will be the following: | ||
* IngressSubnet1: 10.0.0.0/24 | ||
* IngressSubnet2: 10.0.1.0/24 | ||
* IngressSubnet3: 10.0.2.0/24 | ||
* ApplicaitonSubnet1: 10.0.3.0/24 | ||
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. Typo 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. done |
||
* ApplicaitonSubnet2: 10.0.4.0/24 | ||
* ApplicaitonSubnet3: 10.0.5.0/24 | ||
* DatabaseSubnet1: 10.0.6.0/28 | ||
* DatabaseSubnet2: 10.0.6.16/28 | ||
* DatabaseSubnet3: 10.0.6.32/28 | ||
|
||
Each `Public` Subnet will have a NAT Gateway. Each `Private` Subnet will have a | ||
route to the NAT Gateway in the same availability zone. Each `Isolated` subnet | ||
will not have a route to the internet, but is routeable inside the VPC. The | ||
numbers [1-3] will consistently map to availability zones (e.g. IngressSubnet1 | ||
and ApplicaitonSubnet1 will be in the same avialbility zone). | ||
|
||
`Isolated` Subnets provide simplified secure networking principles, but come at | ||
an operational complexity. The lack of an internet route means that if you deploy | ||
instances in this subnet you will not be able to patch from the internet, this is | ||
commonly reffered to as | ||
[fully baked images](https://aws.amazon.com/answers/configuration-management/aws-ami-design/). | ||
Features such as | ||
[cfn-signal](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-signal.html) | ||
are also unavailable. Using these subnets for managed services (RDS, | ||
Elasticache, Redshift) is a very practical use because the managed services do | ||
not incur additional operational overhead. | ||
|
||
Many times when you plan to build an application you don't know how many | ||
instances of the application you will need and therefore you don't know how much | ||
IP space to allocate. For example, you know the application will only have | ||
Elastic Loadbalancers in the public subnets and you know you will have 1-3 RDS | ||
databases for your data tier, and the rest of the IP space should just be evenly | ||
distributed for the application. | ||
|
||
```ts | ||
import { VpcNetwork } from '@aws-cdk/ec2'; | ||
|
||
new VpcNetwork(stack, 'TheVPC', { | ||
cidr: '10.0.0.0/16', | ||
subnetConfiguration: [ | ||
{ | ||
cidrMask: 26, | ||
name: 'Public', | ||
subnetType: SubnetType.Public, | ||
natGateway: true, | ||
}, | ||
{ | ||
name: 'Application', | ||
subnetType: SubnetType.Private, | ||
}, | ||
{ | ||
cidrMask: 27, | ||
name: 'Database', | ||
subnetType: SubnetType.Isolated, | ||
} | ||
], | ||
}); | ||
``` | ||
|
||
The `VpcNetwork` from the above configuration in a Region with three | ||
availability zones will be the following: | ||
* PublicSubnet1: 10.0.0.0/26 | ||
* PublicSubnet2: 10.0.0.64/26 | ||
* PublicSubnet3: 10.0.2.128/26 | ||
* DatabaseSubnet1: 10.0.0.192/27 | ||
* DatabaseSubnet2: 10.0.0.224/27 | ||
* DatabaseSubnet3: 10.0.1.0/27 | ||
* ApplicaitonSubnet1: 10.0.64.0/18 | ||
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. Typo |
||
* ApplicaitonSubnet2: 10.0.128.0/18 | ||
* ApplicaitonSubnet3: 10.0.192.0/18 | ||
|
||
Any subnet configuration without a `cidrMask` will be counted up and allocated | ||
evenly across the remaining IP space. | ||
|
||
Teams may also become cost conscious and be willing to trade availability for | ||
cost. For example, in your test environments perhaps you would like the same VPC | ||
as production, but instead of 3 NAT Gateways you would like only 1. This will | ||
save on the cost, but trade the 3 availability zone to a 1 for all egress | ||
traffic. This can be accomplished with a single parameter configuration: | ||
|
||
```ts | ||
import { VpcNetwork } from '@aws-cdk/ec2'; | ||
|
||
new VpcNetwork(stack, 'TheVPC', { | ||
cidr: '10.0.0.0/16', | ||
natGateways: 1, | ||
subnetConfiguration: [ | ||
{ | ||
cidrMask: 26, | ||
name: 'Public', | ||
subnetType: SubnetType.Public, | ||
natGateway: true, | ||
}, | ||
{ | ||
name: 'Application', | ||
subnetType: SubnetType.Private, | ||
}, | ||
{ | ||
cidrMask: 27, | ||
name: 'Database', | ||
subnetType: SubnetType.Isolated, | ||
} | ||
], | ||
}); | ||
``` | ||
|
||
The `VpcNetwork` above will have the exact same subnet definitions as listed | ||
above. However, this time the VPC will have only 1 NAT Gateway and all | ||
Application subnets will route to the NAT Gateway. | ||
|
||
### Fleet | ||
|
||
A `Fleet` represents a number of instances on which you run your code. You | ||
|
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.
Maybe put this in its own section. "Advanced subnet configuration" or something.
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.
done