bored-river-53178
02/03/2020, 12:23 AMwhite-balloon-205
apply
is the recommended solution. You can pass apply
a function that returns a Promise
, so in particular you can pass it an async
function and use await
inside it is you are looking for the convenience that provides.
It is not recommended to use .promise()
in general - it’s behavior when there are unknown (not yet known) values is harder to work with, and it does not correctly track dependencies or secretness. It is generally treated as an implementation detail - not part of the documented API. In general, apply with an async callback should give you what you need instead.bored-river-53178
02/03/2020, 9:09 AMgetOutputSync
with apply
? I am quite new to javascript and promises so I am not sure what you mean
I want to have all outputs from a stackReference to be assigned to variables at the start of the program, is that possible?many-garden-84306
02/03/2020, 11:47 PMpulumi stack --stack "$(pulumi whoami)/<project-name>/<stack-name>" output --json
white-balloon-205
could you please provide an example of replacingPulumi in Node.js (ike Node.js itself) is fundamentally async, so you cannot do something identical - but you should always be able to express what you need to. I can't tell exactly what code you are trying to write - but here is something that sounds similar that does work:withgetOutputSync
?apply
import * as pulumi from "@pulumi/pulumi";
import * as fs from "fs";
const otherStack = new pulumi.StackReference("other", {
name: "other"
});
otherStack.getOutput("something").apply(async (something) => {
await fs.promises.writeFile("./out.txt", something);
console.log("wrote file");
});
bored-river-53178
02/04/2020, 12:12 AMgetOutputSync
before the latest changes to nodejs.
Right now it seems to me that await Output.promise()
is the easiest way, and since there should be no issues with not yet known values or dependencies in that specific case (referenced stack) the only disadvantage I see could be related to secrets handlingmany-garden-84306
02/04/2020, 12:14 AM