https://pulumi.com logo
#typescript
Title
# typescript
g

gray-hamburger-90102

05/21/2021, 9:27 AM
Hey, is there a nice way here to get all of the route tables for my VPC? As you can see from my attempt, I can't get an array of the routeTable Ids:
Copy code
const vpc = new awsx.ec2.Vpc("BaseNetworkVPC", {
    cidrBlock: "10.50.0.0/22",
    subnets: [
        { type: "public" },
        { type: "private" },
    ],
});

// this is probably wrong, but not sure how to proceed!
const vpcPrivateSubnets = pulumi.output(vpc.privateSubnets).apply(psns => psns.map(psns => psns.routeTable?.id));

// I want to make a routeTable propagation for each of my VPC's private subnets
const routeTablePropagation2 = new aws.ec2.VpnGatewayRoutePropagation("VPGPropagateMainRouteTable", {
        vpnGatewayId: gatewayAssociation.associatedGatewayId,
        routeTableId: // what goes here?
    });
});
More generically - how do I retrieve a collection of resources and then iterate over them to make more resources?
b

brave-planet-10645

05/21/2021, 9:34 AM
Most of our resources have a
getX
function. For route tables, we've got
getRouteTables()
: https://www.pulumi.com/docs/reference/pkg/aws/ec2/getroutetables/#getroutetablesfilter You can pass in the vpc id into the filter arguments and that should return the route tables for that VPC
g

gray-hamburger-90102

05/21/2021, 9:57 AM
A bit further, but now I am not allowed to use the Vpc I made earlier's ID?
Copy code
const privateRouteTables = aws.ec2.getRouteTables({
    vpcId: vpc.id,
    filters: [
        {
            name: 'association.subnet-id',
            values: pulumi.output(vpc.privateSubnetIds).apply(snids => snids)
        }
    ]
});
Copy code
// line 2
Type 'Output<string>' is not assignable to type 'string | undefined'.
  Type 'Output<string>' is not assignable to type 'string'.
b

brave-planet-10645

05/21/2021, 10:14 AM
g

gray-hamburger-90102

05/21/2021, 10:16 AM
I tried this:
vpcId: vpc.id.apply(id => id),
with the exact same error as above
My feeling here is that you can't ever go from
Output<T>
to
T
?
l

little-cartoon-10569

05/23/2021, 9:22 PM
Yes, you need to use the id inside the apply(). You don't return it from the apply.
3 Views