I'm trying to pull the route-table-id from a subne...
# typescript
a
I'm trying to pull the route-table-id from a subnet , and I'm getting a
Object is possibly 'undefined'.
. I get it, it's possible for a route table not to be associated, we're type safe, cool. I tried a few things like
let x: string | undefined
but didn't get very far. what the google foo i need to figure this kind of thing out
Copy code
const allSubnets = vpc.privateSubnets.concat(vpc.publicSubnets)

for (var sn of allSubnets) {
  var rtid = sn.routeTableAssociation.routeTableId;
}
I ended up with something like:
Copy code
const allSubnets = vpc.privateSubnets.concat(vpc.publicSubnets)

let peeringRoutes: aws.ec2.Route[] = [];
let it = 0;
for (var sn of allSubnets) {
  if (sn.routeTableAssociation === undefined) {
    continue;
  }

  peeringRoutes.push(
    new aws.ec2.Route(`vpc-peering-route-${it}`, {
      destinationCidrBlock: "10.200.1.0/24",
      routeTableId: sn.routeTableAssociation.routeTableId,
      vpcPeeringConnectionId: workspaceToC1PeeringConnection.id
    })
  );
  it++;
}