busy-magazine-48939
10/16/2019, 8:25 AMpulumi.Output.apply()
function, in particular I am not sure how to work with pulumu.Output<any>
during preview:
const vpc = new awsx.ec2.Vpc("vpc", {
cidrBlock: '10.0.0.0/16',
enableDnsHostnames: true,
numberOfAvailabilityZones: 1,
subnets: [
{
type: "public",
name: `${prefix}-app`,
location: "10.0.1.0/26",
tags: {
subnetType: "apps", // <-- my custom tag I intent to filter by
...commonTags
}
},
{
type: "public",
name: `${prefix}-osb`,
location: {
cidrBlock: "10.0.20.0/26",
availabilityZone: `${region}a`
},
tags: { subnetType: "osb", ...commonTags }
}
],
tags: { Name: "Collaboration Zone", ...commonTags }
})
const instance = new aws.ec2.Instance("instance", {
tags: { "Name": `${prefix}-instance`, ...commonTags },
instanceType: 't2.large',
vpcSecurityGroupIds: [sg.id],
ami: ami,
subnetId: vpc.publicSubnets // <-- awsx.ec2.Subnet
.filter(subnet => filterSubnetByTag('apps', subnet))
.map(subnet => subnet.id)[0],
keyName: deployer.keyName
})
function filterSubnetByTag(subnetTag: string, subnet: awsx.ec2.Subnet): boolean {
// subnet.subnet.tags is of the following type:
// readonly tags: pulumi.Output<{
// [key: string]: any;
// } | undefined>;
// how do I filter pulumu.Output<any> during preview????
return !!(subnet.subnet.tags.apply(tag => tag && tag.subnetType && tag.subnetType === subnetTag))
}
stocky-island-3676
10/16/2019, 9:56 AMtag["subnetType"] === subnetTag
.
This kind of object is often called a hashmap, if you want to search for it 🙂 (https://stackoverflow.com/a/30019750/1168315).
To be safe, you should also check if there are any tags at all.string
.