Hoping I can get some advice: I’m using the `awsx.vpc` resource to create a VPC, but I now need to ...
s
Hoping I can get some advice: I’m using the
awsx.vpc
resource to create a VPC, but I now need to add a peering connection. What’s the best way to update my route tables? I’m not finding an option inside the
awsx.Vpc
resource. Do I need to switch to manually creating the resources with
aws.ec2.Vpc
,
aws.ec2.Subnet
aws.ec2.RouteTable
, etc or is there a better approach that I’m missing?
l
Yes, you need to update the route tables yourself. I have this, hopefully it'll get you started.
Copy code
Promise.all([this.vpc.publicSubnets, this.vpc.privateSubnets]).then(([publicSubnets, privateSubnets]) => {
      [...publicSubnets, ...privateSubnets].forEach((subnet) => {
        subnet.createRoute(
          `peering-to-${label}`,
          {
            vpcPeeringConnectionId: this.peerConnectionId,
            destinationCidrBlock: cidrBlock
          },
          this.parentOpts(subnet)
        );
      });
    });
This code was written before the various
...Output
methods existed. If they exist for awsx.Vpc, then you can use
apply()
instead of
then()
.
s
Thanks @little-cartoon-10569, appreciate you sharing! Good to know I ended up on the right track - I ended up doing something similar in the end:
Copy code
vpc.routeTables.apply(routeTables => {
    for (const [index, routeTable] of routeTables.entries()) {
      routeTable.tags.apply(tags => {
        if (tags?.SubnetType === 'Private' || tags?.Name?.includes('private')) {
          const route = new aws.ec2.Route(...);
        }
      });
    }
  });