Skip to content
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

(aws_ec2): Unable to create dual-stack VPC if no subnets are defined #31641

Closed
1 task
tpflueger opened this issue Oct 3, 2024 · 8 comments
Closed
1 task
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. p2 p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@tpflueger
Copy link

tpflueger commented Oct 3, 2024

Describe the bug

Our initial CDK setup uses the VPC construct but delays the creation of subnets until later. Note, this worked but it may not be the way CDK is intended to be used. Switching to dual stack IPV4/IPV6, the construct now requires subnets to be defined.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

An ipv6 cidr block to be created that I could use for later subnet creation.

Current Behavior

CDK throws an exception.
Unhandled exception. System.Exception: Fn::Cidr's count attribute must be between 1 and 256, 0 was provided.

Reproduction Steps

new Vpc(parent.Construct, Name, new VpcProps
        {
            IpProtocol = IpProtocol.DUAL_STACK,
            VpcName = _name,
            IpAddresses = IpAddresses.Cidr(_cidrBlock.ToString()),
            DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
            Ipv6Addresses = Ipv6Addresses.AmazonProvided(),
            EnableDnsHostnames = true,
            EnableDnsSupport = true,
            SubnetConfiguration = Array.Empty<SubnetConfiguration>()
        })

Possible Solution

Is subnet now a requirement? If not, it might be useful to allow specifying the Ipv6 CIDR block size.

Additional Information/Context

No response

CDK CLI Version

2.160.0

Framework Version

No response

Node.js Version

v22.1.0

OS

Windows 11

Language

.NET

Language Version

.NET 8.0.402

Other information

No response

@tpflueger tpflueger added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Oct 3, 2024
@ashishdhingra ashishdhingra self-assigned this Oct 3, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2024
@ashishdhingra
Copy link
Contributor

The error is thrown at Ipv6Addresses.amazonProvided() > AmazonProvided.createIpv6CidrBlocks() (invoked from here > Fn.cidr() > FnCidr().

Since AmazonProvided Ipv6Addresses is used, it expects subnet configuration to be created.

@pahud
Copy link
Contributor

pahud commented Oct 4, 2024

yes subnet configuration is like the topology definition of your subnets for this vpc which tells the subnet cidr, subnet count as well as the mask, which is required for createIpv6CidrBlocks.

createIpv6CidrBlocks(input: CreateIpv6CidrBlocksRequest): string[] {
const sizeMask = input.sizeMask ?? '64'; // 128 - 64
return Fn.cidr(input.ipv6SelectedCidr, input.subnetCount, sizeMask);
}

@ashishdhingra
Copy link
Contributor

@pahud Thanks for elaborating the design.

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 4, 2024
@tpflueger
Copy link
Author

tpflueger commented Oct 4, 2024

@pahud Is there a way to delay specifying subnets for IPv6? The creation of the VPC without subnets works until you try to use dual stack. For example, what we are doing is creating the VPC and then separately creating each subnet which works with IPv4. Dual stack puts a requirement of specifying subnets up front.

var vpc = new Vpc(parent.Construct, Name, new VpcProps
        {
            IpProtocol = IpProtocol.DUAL_STACK,
            VpcName = _name,
            IpAddresses = IpAddresses.Cidr(_cidrBlock.ToString()),
            DefaultInstanceTenancy = DefaultInstanceTenancy.DEFAULT,
            Ipv6Addresses = Ipv6Addresses.AmazonProvided(),
            EnableDnsHostnames = true,
            EnableDnsSupport = true,
            SubnetConfiguration = Array.Empty<SubnetConfiguration>()
        })
new CfnSubnet(parent.Construct, $"Subnet-{cidrBlockName}", new CfnSubnetProps
        {
            CidrBlock = _cidrBlock.ToString(),
            AvailabilityZone = _availabilityZone.ToString(),
            VpcId = vpc .RefId,
            MapPublicIpOnLaunch = _isPublic
        })

@pahud
Copy link
Contributor

pahud commented Oct 4, 2024

Can you share your use case why you need to delay the subnet creation?

I guess we just need to understand your use case and hopefully figure out a way to address that through a PR or a workaround.

@tpflueger
Copy link
Author

The current implementation I am working on made constructs of everything and limited the VPC construct to only create the VPC. Subnets were being handled by a separate construct. I can make the changes to allow the VPC construct to create the subnets instead. I was unsure if this was intended behavior due to IPv4 VPC working without specifying subnets initially.

@ashishdhingra
Copy link
Contributor

The current implementation I am working on made constructs of everything and limited the VPC construct to only create the VPC. Subnets were being handled by a separate construct. I can make the changes to allow the VPC construct to create the subnets instead. I was unsure if this was intended behavior due to IPv4 VPC working without specifying subnets initially.

@tpflueger Thanks for the details. Please confirm if we could close this issue since you might have mitigated your use case.

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Oct 7, 2024
Copy link

github-actions bot commented Oct 8, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. p2 p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants