Repository navigation
feat(ec2): support IPAM CIDR allocation for Subnet - #38810
Conversation
|
Exemption Request: I could not deploy the integration test (no AWS account available), so the snapshot for integ.subnet-ipam.ts is not included. The test is written per INTEGRATION_TESTS.md; could a maintainer run it to generate the snapshot? Happy to adjust the test if the pool setup needs changing. |
# Conflicts: # CHANGELOG.v2.alpha.md # CHANGELOG.v2.md # packages/@aws-cdk/metrics-facade-alpha/package.json # packages/@aws-cdk/mixins-preview/package.json # packages/aws-cdk-lib/aws-ec2/test/vpc.test.ts # packages/aws-cdk-lib/package.json # tools/@aws-cdk/spec2cdk/package.json # version.v2.json # yarn.lock
|
@ozelalisen Done, thanks. I updated the second bullet of "Description of how you validated changes" to your wording and dropped the fork-run bullet, since CI on this PR covers the same checks. |
ozelalisen
left a comment
There was a problem hiding this comment.
Thanks for updating the description. Two inline comments are still open: the struct name on vpc.ts (SubnetIpv4IpamAllocation), which can't change after release, and the README note on IPAM discovery timing. Could you take a look at those?
Leaves room for an IPv6 struct in a follow-up. Also clarifies in the README that the planning pool belongs in a later deployment, once IPAM has discovered the VPC.
|
@ozelalisen Thanks, both done:
|
Pull request has been modified.
ozelalisen
left a comment
There was a problem hiding this comment.
Thanks, the rename and the README wording both look good.
|
@Mergifyio update |
❌ GitHub refused to update workflow filesDetailsGitHub response: refusing to allow a GitHub App to create or update workflow |
Pull request has been modified.
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
❌ Left the queue · checks timed out2 h 22 min in the queue, 2 h 21 min of it CI. So far
Reason The merge conditions cannot be satisfied: the checks did not pass within the automatic checks timeout of 2 hours 20 minutes 40 seconds, derived from this queue's recent CI runtime These checks were still running:
To get back in the queue
Merge conditions not met when it left the queue
Requeue requested — the merge queue status continues in this comment ↓. 2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
|
@ozelalisen Thanks for the approval. The merge queue dropped this PR because |
|
@Mergifyio queue |
✅ Merged into
|
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #34296.
Reason for this change
Subnet(andPublicSubnet/PrivateSubnet) require a concretecidrBlock, whileAWS::EC2::Subnetcan allocate its IPv4 CIDR from an Amazon VPC IP Address Manager pool (Ipv4IpamPoolId+Ipv4NetmaskLength).Vpcalready supports IPAM for the VPC CIDR throughIpAddresses.awsIpamAllocation(), but a standalone L2 subnet cannot use IPAM without dropping to the L1, or overriding the L1 properties withCfnSubnetPropsMixinand a placeholdercidrBlock.Description of changes
SubnetProps.cidrBlockbecomes optional and a new optionalipv4IpamAllocation: SubnetIpv4IpamAllocationprop is added, whereSubnetIpv4IpamAllocationis{ ipamPool: IIPAMPoolRef, netmaskLength: number }.Subnetvalidates that exactly one ofcidrBlock/ipv4IpamAllocationis set and thatnetmaskLengthis within /16 to /28 (the IPv4 subnet sizes the package already enforces inNetworkBuilder; skipped for tokens), usingValidationErrorwithlitcodes.Ipv4IpamPoolId/Ipv4NetmaskLengthare passed toCfnSubnet. When IPAM is used,subnet.ipv4CidrBlockisCfnSubnet.attrCidrBlock(a deploy-time token) instead of a concrete string, the same wayVpc.vpcCidrBlockisattrCidrBlockfor an IPAM-allocated VPC.Design decisions, flagged for review:
ipv4IpamPoolId/ipv4NetmaskLength: the two values are only valid together (co-dependent props rule indocs/AGENTS_CONSTRUCT_DESIGN.md). Exclusivity with the pre-existingcidrBlockcannot be made structural without adding a second, factory-style way to express the CIDR, so it is validated at construction time as proposed in the issue.ipamPool: IIPAMPoolRefrather than an ID string, following the preference forI*Refinterfaces in props (as inplacementGroup?: IPlacementGroupRef,networkAcl: INetworkAclRef).CfnIPAMPoolimplements it directly andCfnIPAMPool.fromIpamPoolId()covers pools created elsewhere.AwsIpamProps.ipv4IpamPoolIdis still astring(with a "todo: should be a type" comment); happy to switch to a string if consistency with it is preferred.netmaskLengthis required, mirroringAwsIpamProps.ipv4NetmaskLength; relaxing it to optional later is non-breaking.cidrBlockrequired,ipv4CidrBlockderived from it), which a mixin must not change.CfnSubnetPropsMixinremains the escape hatch, e.g. for IPv6 IPAM allocation, which is left for a follow-up.ipv4CidrBlockthat parse the CIDR (SubnetFilter.byCidrMask(),byCidrRanges(),containsIpAddresses()) cannot work with a deploy-time value; this is documented on the prop and in the README rather than changed. Subnets created byVpcfromsubnetConfigurationare untouched.cidrBlockoptional on an input struct is source-compatible for callers;PublicSubnetProps/PrivateSubnetPropsinherit the new prop.Alternatives considered and rejected: flat props (co-dependent rule); a
SubnetIpAddresses.cidr()/.ipam()factory prop mirroringVpc.ipAddresses(cidrBlockalready exists and cannot be removed); optionalnetmaskLengthusing the pool's default netmask as in #34349 (deferred).Describe any new or updated permissions being added
None. No IAM policies are created; the allocation uses the deploying principal's existing EC2/IPAM permissions.
Description of how you validated changes
packages/aws-cdk-lib/aws-ec2/test/vpc.test.ts(describe('Subnet')): the concrete-CIDR path renders exactly as before (CidrBlock, no IPAM properties); the IPAM path rendersIpv4IpamPoolId/Ipv4NetmaskLengthand noCidrBlock, both withCfnIPAMPool.fromIpamPoolId()and with a pool defined in the same stack;ipv4CidrBlockresolves toFn::GetAtt [<subnet>, CidrBlock];PublicSubnet/PrivateSubnetaccept the prop (includingaddNatGateway()); a tokennetmaskLengthis passed through; the three validation errors.packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.subnet-ipam.ts: an Advanced Tier IPAM, a VPC with10.0.0.0/16, a custom resource that waits until IPAM has discovered the VPC, a resource planning pool for the VPC, and aSubnetwithipv4IpamAllocation. AnawsApiCall('EC2', 'describeSubnets')assertion checks that the allocated CIDR is10.0.0.0/24. A maintainer deployed the test and committed the snapshot.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license