Skip to content

spec2cdk: Breaking changes in Aws-cdk-lib-java from Tagging Change #29869

@GavinZZ

Description

@GavinZZ

Describe the bug

#28989
This PR caused breaking change in aws-cdk-lib-java package since v2.136.0.

public class CdkJavaStack extends Stack {
    public CdkJavaStack(final Construct scope, final String id) {
        this(scope, id, null);
    }

    public CdkJavaStack(final Construct scope, final String id, final StackProps props) {
        super(scope, id, props);

        CfnVPC vpc = CfnVPC.Builder
            .create(this, "MyVpc")
            .enableDnsHostnames(true)
            .enableDnsSupport(true)
            .instanceTenancy("default")
            .build();

        List<CfnSubnet> subnets = new ArrayList<>();
        CfnSubnet subnet = new CfnSubnet(this,
            "PublicSubnets",
            CfnSubnetProps.builder()
                    .vpcId(vpc.getRef())
                    .mapPublicIpOnLaunch(false)
                    .tags(List.of(CfnTag.builder().key("MyKey").value("MyValue").build()))
                    .build());

        subnets.add(subnet);

        System.out.println(subnets.get(0).getTags().tagValues());
        String natGatewayName = subnets.get(0).getTags().tagValues().get("MyKey") + "-NatGateway";
        CfnNatGateway natGateway = CfnNatGateway.Builder
            .create(this, natGatewayName)
            .subnetId(subnets.get(0).getRef())
            .tags(List.of(CfnTag.builder().key("MyKey").value(natGatewayName).build()))
            .build();
    }
}

Expected Behavior

In cdk version v.120.0, the line String natGatewayName = subnets.get(0).getTags().tagValues().get("MyKey") + "-NatGateway"; will correctly generate the name.

Current Behavior

However, in v.136.0, this would result in Null-NateGateway. And it's causing breaking changes.

Reproduction Steps

See above template.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

v.136.0

Framework Version

No response

Node.js Version

20

OS

MacOS

Language

Java

Language Version

No response

Other information

No response

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 effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions