This message was deleted.
# python
s
This message was deleted.
h
Able to figure it
Copy code
private_route_table_details = mws_vpc.route_tables.apply(
                lambda route_tables: [
                    private_id
                    for route in route_tables
                    if (
                        private_id := route.tags.apply(
                            lambda tag: route.id
                            if tag["SubnetType"] == "Private"
                            else None
                        )
                    )
                ],
            )
But list contain <null> which i cannot remove it with None or "null", "" check
g
I've arrived at the same conclusion as you. I'm not able to properly filter out the null values but am checking into that one.
👍 1
h
@green-stone-37839 any luck
g
Yes actually. I'll need a couple of hours (early AM for me) but I'll drop a solution in a bit.
🙌 1
This solution is typescript based (my python is rusty). Hopefully this gives you an idea of what is needed to get want you want. Essentially two steps: 1. unwrap the tags from the route table 2. filter based on needed tags
Copy code
function GetPrivateVpcs(rts: aws.ec2.RouteTable[]): pulumi.Output<aws.ec2.RouteTable | undefined>[] {
    const privateRts: pulumi.Output<aws.ec2.RouteTable | undefined>[] = [];

    for (const rt of rts) {
        const localRt = rt.tags.apply(tag => {

            if (tag!["SubnetType"] == "Private") {
                console.log("Private");
                console.log(`length: ${privateRts.length}`);
                return rt;
            }

            return undefined;
        });

        privateRts.push(localRt);
    }

    return privateRts;
}

const vpc = new awsx.ec2.Vpc("vpc", {
    cidrBlock: "10.100.0.0/16"
});

export const privateRts = vpc.routeTables.apply(GetPrivateVpcs);
This is the working function. Replace GetPrivateVpcs above with the below
Copy code
function GetPrivateVpcs(
  rts: aws.ec2.RouteTable[]
): pulumi.Output<aws.ec2.RouteTable[]> {
  // Resolve all outputs first, then filter within the apply.
  return pulumi
    .all(
      rts.map((rt) =>
        rt.tags.apply((tags) => ({
          rt,
          tags,
        }))
      )
    )
    .apply((unwrapped) => {
      const privateRts: aws.ec2.RouteTable[] = [];

      for (const rt of unwrapped) {
        if (rt.tags!["SubnetType"] == "Private") {
          console.log("Private");
          console.log(`length: ${privateRts.length}`);
          privateRts.push(rt.rt);
        }
      }

      return privateRts;
    });
}