hey friends - if I have a secret that I want to wr...
# typescript
f
hey friends - if I have a secret that I want to write to a file, for example as input to cloud-init - how do I do that? I get an error that says I should use
apply
... but that doesn't seem to actually let me wind up with a string 🙂
g
You can provide the return object from the
.apply
directly to a resource input - e.g.
userData
on an
aws.ec2.Instance
.
f
my problem is I'm composing it with other data, I suspect - so my userdata is an interpolated string, and I can't get a value of out
apply
that seems to ever show up in that string
do I need to basically nest
apply
, and then pass the resulting output (which will eventually resolve to what pulumi needs) to the userData?
g
You can use
.all(...).apply(...)
to combine multiple values into an interpolated string. Here's a contrived, but functional example:
Copy code
const config = new pulumi.Config()
const mySecret = config.requireSecret("mySecret");

// create the string `vpc-abc123: asdf1234`
const userData = pulumi.all([vpc.id, mySecret]).apply(([vpcId, secret]) => `${vpcId}: ${secret}`);
But if you only have a single output that you're interpolating you can use `pulumi.interpolate`:
Copy code
// create the string `password: asdf1234`
const userData = pulumi.interpolate`password: ${mySecret}`
f
I see - they're promises
thank you so much @gentle-diamond-70147 - that solved my problem!
🎉 1
👍 1
s
@flaky-father-99093 there’s also a helpful little library for generating cloud init manifests in typescript that joe wrote: https://github.com/joeduffy/pcloudinit