Skip to content

(ec2.Vpc): Vpc.fromLookup should throw if subnet group name tag is explicitly given and does not exist #13962

@1oglop1

Description

@1oglop1

I suspect this may be a bug or I'm missing something.

I have an existing VPC with 6 subnets with a tag subnet_tier

AZ1 AZ2 TAG: subnet_tier
public_subnet_1 public_subnet_2 public
private_subnet_1 private_subnet_2 private
data_subnet_1 data_subnet_2 data

From my understanding of Vpc.from_lookup I can supply subnet_group_name_tag will assign the subnets to the correct group inside cdk.context.json
So I can then create a SubnetSelection expected by multiple resources (eg. Function)
So when I add following code in my stack I get an error.

vpc = Vpc.from_lookup(
                self,
                "VPC",
                vpc_id="vpc-123456",
                subnet_group_name_tag="subnet_tier",
            )
subnets = vpc.select_subnets(subnet_group_name='data').subnets

PythonFunction(
    self,
    "Function",
    ...
    vpc=vpc,
    vpc_subnets=subnets
)

Actual result

cdk.context.json is created with SubnetGroups

"subnetGroups": [
      {
        "name": "Private",
        "type": "Private",
       },
             {
        "name": "public",
        "type": "Public",
        }
]

Error message raised:

jsii.errors.JSIIError: You cannot reference a Subnet's availability zone if it was not supplied. Add the availabilityZone when importing using Subnet.fromSubnetAttributes()

Expected result

"subnetGroups": [
      {
        "name": "private",
        "type": "Private",
       },
      {
        "name": "data",
        "type": "Private",
       },
            {
        "name": "public",
        "type": "Public",
        }
]

No errors.

Environment

  • CDK CLI Version: 1.96.0 (build 39f3df8)
  • Module Version: ec2
  • Node.js Version: N/A python CDK 1.96.0
  • OS: macOS
  • Language (Version): Python (3.8.6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions