quick-hospital-63970
08/07/2023, 2:40 AMawsx.ec2.Vpc
). The vpc
object exposes privateSubnetIds
and subnets
- I was hoping to combine the two using code like the below. However, it complains that subnet.id
is Output<string>
and includes()
of course expects a string
. Is this something which is possible? The alternative is to re-query the subnets using aws.ec2.getSubnet
, but that feels kind of iffy/unnecessary, when the subnets are already available on the vpc
object.
export const privateSubnetCidrs = pulumi
.all([vpc.subnets, vpc.privateSubnetIds])
.apply(([subnets, privateSubnetIds]) => {
return subnets
.filter(subnet => privateSubnetIds.includes(subnet.id))
.map(subnet => subnet.cidrBlock);
});
privateSubnets
field on vpc
:
// Map over the private subnets and retrieve the cidrBlocks
const privateSubnetCidrs = vpc.privateSubnets.apply(privateSubnets =>
privateSubnets.map(subnet => subnet.cidrBlock)
)
little-cartoon-10569
08/07/2023, 2:49 AMquick-hospital-63970
08/07/2023, 2:50 AMexport const privateSubnetCidrs = pulumi
.all([vpc.subnets, vpc.privateSubnetIds])
.apply(([subnets, privateSubnetIds]) => {
const cidrBlocks: string[] = [];
for (const subnet of subnets) {
pulumi
.all([subnet.id, subnet.cidrBlock])
.apply(([subnetId, cidrBlock]) => {
if (privateSubnetIds.includes(subnetId) && cidrBlock) {
cidrBlocks.push(cidrBlock);
}
});
}
return cidrBlocks;
});
little-cartoon-10569
08/07/2023, 2:50 AMquick-hospital-63970
08/07/2023, 2:50 AMprivateSubnetIds
, but NOT privateSubnets
little-cartoon-10569
08/07/2023, 2:50 AM/**
* Asynchronously retrieves the private subnets in this Vpc. This will only retrieve data for
* the subnets specified when the Vpc was created. If subnets were created externally, they
* will not be included.
*/
get privateSubnets(): Promise<x.ec2.Subnet[]>;
quick-hospital-63970
08/07/2023, 2:53 AMlittle-cartoon-10569
08/07/2023, 2:55 AMquick-hospital-63970
08/07/2023, 2:55 AMlittle-cartoon-10569
08/07/2023, 2:56 AMapply()
. However it looks like you can skip filtering by subnetId. You can just filter on subnets, which have a type property whose lowercase value will be private.
https://github.com/pulumi/pulumi-awsx/blob/dad5462435286498bc86168c91c0d801482dbcba/awsx/ec2/subnetDistributor.ts#L52quick-hospital-63970
08/07/2023, 3:07 AMpulumi.Output
and I don’t have time to figure out what’s happening 😞