calm-quill-21760
02/19/2020, 7:38 PMlet vpcList = vpcConfig.map(entry => {
return new aws.ec2.Vpc(entry.name, {cidrBlock: entry.cidrBlock, tags: {Name: entry.name}});
});
let vpcNameToId: { [index: string]: any } = {};
for (let vpc of vpcList) {
// create a lookup
const vpcName = vpc.tags.apply(v => v?.Name ?? null);
vpcName.apply(theName => {
console.log("Applying " + theName + "=" + vpc.id.apply(v => `${v}`));
// vpcNameToId[theName] = vpcId;
});
}
Results in:
Applying vpc0=Calling [toString] on an [Output<T>] is not supported.
To get the value of an Output<T> as an Output<string> consider either:
1: o.apply(v => `prefix${v}suffix`)
2: pulumi.interpolate `prefix${v}suffix`
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi.
gorgeous-egg-16927
02/19/2020, 8:31 PMpulumi.all
to resolve all the outputs.
(not tested, but should be close)
pulumi.all([vpcName, vpc.id]).apply(([name, id]) => console.log(`Applying ${name} = ${id}`))
calm-quill-21760
02/19/2020, 8:43 PMlet vpcNameToId: { [index: string]: any } = {};
for (let vpc of vpcList) {
// create a lookup table
const vpcName = vpc.tags.apply(v => v?.Name ?? null);
const vpcId = vpc.id;
pulumi.all([vpcName, vpcId]).apply(([name, id]) => {
vpcNameToId[name] = id;
});
}
console.log("" + Object.keys(vpcNameToId).length);
Here the console output is zero items.gorgeous-egg-16927
02/19/2020, 9:02 PMvpmNameToId
into an Output and passing it into the pulumi.all
. At that point, you can resolve that output as usual like
vpcNameToId.apply(map => console.log(Object.keys(map).length))
calm-quill-21760
02/19/2020, 10:03 PMgorgeous-egg-16927
02/21/2020, 9:56 PMwhite-balloon-205
pulumi.output(x)
is effectively Promise.resolve(x)
but for outputs.As I puzzle through this, I end up with "apply" inside "apply" statements just to ensure everything is resolved.This should not be the case in general - though depends a bit on specific code you are trying to write.
calm-quill-21760
02/21/2020, 9:58 PMwhite-balloon-205
apply
. TypeScript doesn't provide any way to offer generalized await
-style syntax (in a pleasent way) over non-promises.calm-quill-21760
02/21/2020, 10:02 PMwhite-balloon-205
pulumi.all(var).apply()
is reasonably commonly needed.calm-quill-21760
02/21/2020, 11:07 PM