Stack Exchange
AWS CDK Vpc.GetPublicSubnets() returning incorrect number of public subnets
Working with AWS CDK JAVA.
I'm creating a VPC with a CIDR of /26 and four Public subnets of CIDR /28 spread over 4 AZs.
SubnetConfiguration subnetConfiguration = null;
    subnetConfiguration = SubnetConfiguration.builder()
            .name(("SN-" + propertyObject.getCoreProjectNumber() + propertyObject.getCoreSiteId()).toLowerCase())
            .subnetType(software.amazon.awscdk.services.ec2.SubnetType.PUBLIC)
            .cidrMask(28)
            .build();
    List<SubnetConfiguration> subnetList = new ArrayList<SubnetConfiguration>();
    subnetList.add(subnetConfiguration);
    vpc = Vpc.Builder.create(this, ("VPC-" + propertyObject.getCoreProjectNumber() + propertyObject.getCoreSiteId()).toLowerCase())
            .cidr(26)
            .enableDnsHostnames(false)
            .maxAzs(4)
            .subnetConfiguration(subnetList)
            .vpnGateway(false)
            .build();

This is creating a VPC as expected with 4 Public Subnets of CIDR /28 spread over 4 AZs.
When I then access the same VPC using this code:
    List<String> subnetIdList=new ArrayList<String>();
    for(ISubnet subnet: vpc.getPublicSubnets()) {
        subnetIdList.add(subnet.getSubnetId());
    }       
System.out.println(subnetIdList);

it returns exactly 3 public subnets.

VPC99999/vpc-99999awuse1/sn-99999awuse1Subnet1
VPC99999/vpc-99999awuse1/sn-99999awuse1Subnet2
VPC99999/vpc-99999awuse1/sn-99999awuse1Subnet3

I'm at my wits end here.  Anyone know what I'm doing wrong or if there is a bug here?
Thanks,
Mike

UGH! Nevermind. The problem is not a CDK bug, but rather an Eclipse compiler bug. In the IDE, the problem is present, but when you compile with Maven and do a CDK Synth everything is fine. – Michael Thomsen
