https://pulumi.com logo
#typescript
Title
# typescript
f

flaky-father-99093

01/07/2020, 1:28 AM
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

gentle-diamond-70147

01/07/2020, 1:31 AM
You can provide the return object from the
.apply
directly to a resource input - e.g.
userData
on an
aws.ec2.Instance
.
f

flaky-father-99093

01/07/2020, 1:35 AM
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

gentle-diamond-70147

01/07/2020, 1:56 AM
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

flaky-father-99093

01/07/2020, 3:58 AM
I see - they're promises
thank you so much @gentle-diamond-70147 - that solved my problem!
🎉 1
👍 1
s

stocky-spoon-28903

01/07/2020, 5:57 PM
@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