1

I've created a VPC like this

    vpc = new Vpc(theStack, vpcName,
        VpcProps.builder()
            .cidr("10.0.0.0/16")
            .build());

In eu-west-1, by default I get 3 public and 3 private subnets. The private subnets will have a NAT Gateway.

Now, we're trying to remove the NAT Gateways (because of cost), so I tried this

    vpc = new Vpc(theStack, vpcName,
        VpcProps.builder()
            .maxAzs(3)
            .cidr("10.0.0.0/16")
            .subnetConfiguration(List.of(
                SubnetConfiguration.builder()
                    .subnetType(SubnetType.PUBLIC)
                    .name("Public")
                    .cidrMask(24)
                    .build(),
                SubnetConfiguration.builder()
                    .subnetType(SubnetType.ISOLATED)
                    .name("Private")
                    .cidrMask(24)
                    .build()))
            .build());

Creating this in a fresh stack works fine. I get a VPC with the same subnets as before and no NAT GW:s. But, running this to modify the VPC created above, results in name clashes.

Is there some way I can get cdk/cloudformation to understand that I want to modify the existing private subnets and not create new ones?

Jörgen Lundberg
  • 1,799
  • 3
  • 22
  • 31

1 Answers1

1

I double-checked the subnets that where created without specifying the subnets. The cdir-mask was /19 not /24 like i entered in the second version.

So, changing the cidrMask to 19 works fine. Now CloudFormation doesn't create new subnets and deletes the NAT Gateways.

Jörgen Lundberg
  • 1,799
  • 3
  • 22
  • 31