Hi, can anyone tell me how to render cloud-init us...
# typescript
g
Hi, can anyone tell me how to render cloud-init user data (yaml) from TS objects, including outputs?
1
l
The key to your solution lies with
pulumi.all([outputs]).apply(callbackFn)
. https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#all Starting from outputs needed for the calculation of the user data, you pass these to
all
as a list, then call
apply
passing it a callback function. The callback function will be invoked by Pulumi by the time the actual values of your outputs are known. The arguments to your callback function will be the actual values that you can use to calculate the user data. The value of the user data is the return value of the callback function.
apply
will wrap this again in an
Output
which you can then pass to the resource taking this as an
Input
, e.g. an AWS EC2 resource. Hope my explanation makes sense.
g
Thank you! In the end, I remembered that I have to convert the object into the output then I could use
js-yaml
library to render the yaml.
Copy code
const cloudInitYaml = pulumi.output(cloudInitConfig).apply(yaml.dump);