Skip to content

aws-servicecatalog: VPC product created with L2 ec2.Vpc not generating subnets #34588

Open
@ryan-roberts-bt

Description

@ryan-roberts-bt

Describe the bug

VPC product created with L2 aws-ec2.Vpc construct with subnet configuration supplied in a aws-servicecatalog.ProductStack class ignores the subnet configuration supplied when generating the template.

Regression Issue

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

Last Known Working CDK Library Version

No response

Expected Behavior

All configuration options supplied to the aws-ec2.Vpc construct should be adhered to when the product cloudformation template is synthesized

Current Behavior

Subnet configuration is ignored and no subnets are created in the synthesized template

Reproduction Steps

from aws_cdk import (
    Stack,
    aws_servicecatalog as servicecatalog,
    aws_ec2 as ec2,
    aws_iam as iam,
    CfnParameter,
)
from constructs import Construct

class VpcServiceCatalogPortfolioStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        vpc_portfolio = servicecatalog.Portfolio(self, "VPC_Portfolio",
                                            display_name="VPC Portfolio",
                                            provider_name="Engineering Team",
                                            description="Pre-configured VPCs available for various use cases including connectivity to the internet and other tenants.",
                                        )
        
        isolated_vpc_stack_history = servicecatalog.ProductStackHistory(self, "IsolatedVpcStackHistory",
                                                                        product_stack=IsolatedVpc(self, "Isolated_VPC"),
                                                                        current_version_name="v1",
                                                                        current_version_locked=False,
                                                                        )
        
        isolated_vpc_product = servicecatalog.CloudFormationProduct(self, "IsolatedVpcProduct",
                                                                    product_name="Isolated/Sandbox VPC",
                                                                    owner="Engineering",
                                                                    product_versions=[
                                                                        isolated_vpc_stack_history.current_version()
                                                                    ]
                                                                    )
        
        vpc_portfolio.add_product(isolated_vpc_product)
        
        launch_role = iam.Role.from_role_name(self, "LaunchRole",
                                              role_name="RES-ServiceCatalog-VPC-Launch")
        
        vpc_portfolio.set_local_launch_role(isolated_vpc_product, launch_role)


class IsolatedVpc(servicecatalog.ProductStack):
    def __init__(self, scope, id):
        super().__init__(scope, id)
        
        availability_zone_param = CfnParameter(self, "AvailabilityZoneNumber",
                                               description="The number of availability zones that this VPC should span",
                                               type="Number",
                                               min_value=1,
                                               max_value=3,
                                               )
        
        
        vpc = ec2.Vpc(self, "VPC",
                      ip_addresses=ec2.IpAddresses.cidr("10.254.0.0/22"),
                      max_azs=availability_zone_param.value_as_number,
                      subnet_configuration=[
                          ec2.SubnetConfiguration(
                              cidr_mask=24,
                              name='private',
                              subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
                          ),
                          ec2.SubnetConfiguration(
                              cidr_mask=24,
                              name='public',
                              subnet_type=ec2.SubnetType.PUBLIC
                          )],
                      enable_dns_support=True,
                      enable_dns_hostnames=True,
                      restrict_default_security_group=False,
                      create_internet_gateway=True,
                      vpn_gateway=False
                      )

Possible Solution

No response

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.199.0

AWS CDK CLI version

2.1007.0

Node.js Version

22.15.0

OS

Windows 11

Language

Python

Language Version

3.12.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions