Skip to content

(aws-ec2): Allow selecting subnets by Id or CIDR mask #15228

@ABevier

Description

@ABevier

I would like the ability to create a SubnetSelection based on the exact subnet ids or based or the CIDR range of subnets in a VPC. While SubnetSelection does allow specifying a list of explicit subnets to use, these use cases are probably common enough support first class without requiring a "custom" filter.

Use Case

I would like this feature because some of the VPC's I'm using have multiple public and private subnets with different CIDR masks and the current subnet selection capability forces me to write my own filters on the list of ISubnets in the vpc and then pass them explicitly to the SubnetSelection.

Proposed Solution

Ideally I would like to do something like this:

    const vpc = Vpc.fromLookup(this, "Vpc", {
      vpcId: props.vpcId,
    });

    const subnetsById: SubnetSelection = {
      subnetFilters: [SubnetFilter.byId('subnet-abc', 'subnet-efg', 'subnet-hij')]
    }

or something like this:

    const vpc = Vpc.fromLookup(this, "Vpc", {
      vpcId: props.vpcId,
    });

    const subnetsByCidr: SubnetSelection = {
      subnetFilters: [SubnetFilter.withCidrMask('26')]
    }
  • 👋 I may be able to implement this feature request

This is a 🚀 Feature Request

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute Cloudeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions