(aws-cdk-lib/aws-ec2): Misleading error "There are no <SubnetType> subnet groups in this VPC. Available types:" when no availability zones are provided #32451
Labels
@aws-cdk/aws-ec2
Related to Amazon Elastic Compute Cloud
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p2
Describe the bug
When one uses the
ec2.Vpc
construct and supplies an empty list ofavailabilityZones
, this results in no subnets actually being created in the VPC due to the loop here. If one then tries to create a VPC Endpoint or NAT Gateway in one of the VPCs they have configured, they will get an error such asThere are no 'Private' subnet groups in this VPC. Available types:
, which can be a bit confusing since there were private subnets configured (but they didn't end up being created).Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
When someone provides an empty availabilityZones list along with a subnet configuration, this should probably result in an error being thrown since this is a nonsensical configuration, which may lead to either missing subnets or misleading errors in further infra configuration down the line.
Current Behavior
The nonsensical configuration is silently accepted and leads to CDK not acting on the customer's configured subnets, or a different misleading error when later trying to create things in one of these subnets.
Reproduction Steps
The following VPC construct reproduces the error:
In this case providing
availabilityZones: [],
is explicit and is a clear bug, but the issue is not caught at that point in the construct initialization. Rather it is raised later when trying to create the requested S3 gateway endpoint.In reality, the code which this example was extracted from retrieves the availability zones to use dynamically, which obscures the real issue from being this obvious.
Possible Solution
Add validation to throw an error when a
Vpc
is initialized with an emptyavailabilityZones
listAdditional Information/Context
No response
CDK CLI Version
2.171.1 (build a95560c)
Framework Version
No response
Node.js Version
18.x
OS
MacOS Sonoma 14.7 (23H124)
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: