Add an accessor to the Internet Gateway that was created by the Vpc construct.
Trying to add a PublicSubnet to an existing Vpc (with existing public subnets), there is no way to create a route to the Vpc's existing Internet Gateway, because the reference is not exposed anywhere (that I could find), so the PublicSubnet is not effectively public.
PublicSubnet constructor automagically create the route from the VPC it's a part of.(Or, ideally, both)
I'd take a workaround within CDK, that allows this without creating (and paying for) a second IGW...
This is a :rocket: Feature Request
Update - I found my workaround, using an escape hatch to get the "IGW" child resource in the Vpc construct:
const igw = vpc.node.findChild('IGW') as CfnInternetGateway;
new CfnRoute(this, 'IGW', {
routeTableId: subnet.routeTable.routeTableId,
destinationCidrBlock: '0.0.0.0/0',
gatewayId: igw.ref,
});
Glad you could figure it out! :) Closing this issue. Feel free to reopen.
Having a stab at this, hope to have a PR out soon.
Most helpful comment
Update - I found my workaround, using an escape hatch to get the "IGW" child resource in the
Vpcconstruct: