You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(ec2): Vpc supports allocating CIDR from AWS IPAM (#22458)
Allows Vpc to Use [Aws IPAM](https://docs.aws.amazon.com/vpc/latest/ipam/what-it-is-ipam.html) for Ip address assignment:
```ts
import { IpAddresses } from '@aws-cdk/aws-ec2';
declare const pool: ec2.CfnIPAMPool;
new ec2.Vpc(stack, 'TheVPC', {
ipAddresses: ec2.IpAddresses.awsIpamAllocation({
ipv4IpamPoolId: pool.ref,
ipv4NetmaskLength: 18,
defaultSubnetIpv4NetmaskLength: 24
})
});
```
This is useful for enterprise users that wish to adopt the benefits of centralised IP address management.
It introduces `ipAddresses` property to allow the new configuration.
----
Thanks to @rix0rrr for support on this.
---
closes#21333
----
#22443 - Issue adds a fix to allow the clean up of the AWS Ipam resource used in ingeg-test testing. Would be better to implement something like this later. for now disclaimer added to integ-test clean up needed on Ipam.
----
### All Submissions:
* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)
### New Features
* [X] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The VPC spans a supernet IP range, which contains the non-overlapping IPs of its contained subnets. Possible sources for this IP range are:
223
+
224
+
* You specify an IP range directly by specifying a CIDR
225
+
* You allocate an IP range of a given size automatically from AWS IPAM
226
+
227
+
By default the Vpc will allocate the `10.0.0.0/16` address range which will be exhaustively spread across all subnets in the subnet configuration. This behavior can be changed by passing an object that implements `IIpAddresses` to the `ipAddress` property of a Vpc. See the subsequent sections for the options.
228
+
229
+
Be aware that if you don't explicitly reserve subnet groups in `subnetConfiguration`, the address space will be fully allocated! If you predict you may need to add more subnet groups later, add them early on and set `reserved: true` (see the "Advanced Subnet Configuration" section for more information).
230
+
231
+
#### Specifying a CIDR directly
232
+
233
+
Use `IpAddresses.cidr` to define a Cidr range for your Vpc directly in code:
234
+
235
+
```ts
236
+
import { IpAddresses } from'@aws-cdk/aws-ec2';
237
+
238
+
newec2.Vpc(stack, 'TheVPC', {
239
+
ipAddresses: ec2.IpAddresses.cidr('10.0.1.0/20')
240
+
});
241
+
```
242
+
243
+
Space will be allocated to subnets in the following order:
244
+
245
+
* First, spaces is allocated for all subnets groups that explicitly have a `cidrMask` set as part of their configuration (including reserved subnets).
246
+
* Afterwards, any remaining space is divided evenly between the rest of the subnets (if any).
247
+
248
+
The argument to `IpAddresses.cidr` may not be a token, and concrete Cidr values are generated in the synthesized CloudFormation template.
249
+
250
+
#### Allocating an IP range from AWS IPAM
251
+
252
+
Amazon VPC IP Address Manager (IPAM) manages a large IP space, from which chunks can be allocated for use in the Vpc. For information on Amazon VPC IP Address Manager please see the [official documentation](https://docs.aws.amazon.com/vpc/latest/ipam/what-it-is-ipam.html). An example of allocating from AWS IPAM looks like this:
253
+
254
+
```ts
255
+
import { IpAddresses } from'@aws-cdk/aws-ec2';
256
+
257
+
declareconst pool:ec2.CfnIPAMPool;
258
+
259
+
newec2.Vpc(stack, 'TheVPC', {
260
+
ipAddresses: ec2.IpAddresses.awsIpamAllocation({
261
+
ipv4IpamPoolId: pool.ref,
262
+
ipv4NetmaskLength: 18,
263
+
defaultSubnetIpv4NetmaskLength: 24
264
+
})
265
+
});
266
+
```
267
+
268
+
`IpAddresses.awsIpamAllocation` requires the following:
269
+
270
+
*`ipv4IpamPoolId`, the id of an IPAM Pool from which the VPC range should be allocated.
271
+
*`ipv4NetmaskLength`, the size of the IP range that will be requested from the Pool at deploy time.
272
+
*`defaultSubnetIpv4NetmaskLength`, the size of subnets in groups that don't have `cidrMask` set.
273
+
274
+
With this method of IP address management, no attempt is made to guess at subnet group sizes or to exhaustively allocate the IP range. All subnet groups must have an explicit `cidrMask` set as part of their subnet configuration, or `defaultSubnetIpv4NetmaskLength` must be set for a default size. If not, synthesis will fail and you must provide one or the other.
275
+
220
276
### Advanced Subnet Configuration
221
277
222
278
If the default VPC configuration (public and private subnets spanning the
@@ -227,9 +283,9 @@ subnet configuration could look like this:
227
283
228
284
```ts
229
285
const vpc =newec2.Vpc(this, 'TheVPC', {
230
-
// 'cidr' configures the IP range and size of the entire VPC.
231
-
// The IP space will be divided over the configured subnets.
232
-
cidr: '10.0.0.0/21',
286
+
// 'IpAddresses' configures the IP range and size of the entire VPC.
287
+
// The IP space will be divided based on configuration for the subnets.
288
+
ipAddresses: IpAddresses.cidr('10.0.0.0/21'),
233
289
234
290
// 'maxAzs' configures the maximum number of availability zones to use.
235
291
// If you want to specify the exact availability zones you want the VPC
@@ -948,11 +1004,11 @@ new ec2.Instance(this, 'Instance2', {
By default, EC2 UserData is run once on only the first time that an instance is started. It is possible to make the
1410
-
user data script run on every start of the instance.
1466
+
user data script run on every start of the instance.
1411
1467
1412
-
When creating a Windows UserData you can use the `persist` option to set whether or not to add
1468
+
When creating a Windows UserData you can use the `persist` option to set whether or not to add
1413
1469
`<persist>true</persist>`[to the user data script](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html#user-data-scripts). it can be used as follows:
0 commit comments