hallowed-fireman-90476
01/03/2024, 6:56 PMmws_vpc = awsx.ec2.Vpc()
private_route_table_details = mws_vpc.route_tables.apply(
lambda rts: [
rt.id
for rt in rts
if rt.tags and rt.tags.get("SubnetType") == "Private"
]
)
export("private_route_table_details", private_route_table_details)
Working using get, which i am trying to avoid
# Option2: Use the get_route_tables function to retrieve all route tables for the specified VPC
# route_tables = aws.ec2.get_route_tables(
# filters=[
# aws.ec2.GetRouteTablesFilterArgs(
# name="vpc-id", values=[mws_vpc.vpc_id]
# ),
# # Filter to include only non-main association route tables, which are considered private
# aws.ec2.GetRouteTablesFilterArgs(
# name="tag:SubnetType", values=["Private"]
# ),
# ]
# )
# private_route_table_ids = []
# for i in route_tables.ids:
# private_route_table_ids.append(i)
hallowed-fireman-90476
01/04/2024, 2:56 AMprivate_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", "" checkgreen-stone-37839
01/04/2024, 6:47 PMhallowed-fireman-90476
01/05/2024, 2:42 PMgreen-stone-37839
01/05/2024, 2:51 PMgreen-stone-37839
01/09/2024, 12:18 AMfunction 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);
green-stone-37839
01/09/2024, 12:19 AMfunction 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;
});
}