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

big-notebook-65054

07/22/2022, 6:57 PM
Hi, I'm having some trouble getting a random password into a string I can use within the code. It says to use
password.result
but that doesn't seem to ever change from a
pulumi.Output<string>
type.
Copy code
const password = new random.RandomPassword(`random-password-${stack}`, { length: 16 });
To get into the specifics more, I am trying to place this password output into a config file on an EC2 instance by inserting it into the userData script. Every time I check the new EC2 server I get this error in the logs:
Copy code
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./"
In the docs it says
Because outputs are asynchronous, their actual raw values are not immediately available.
which makes sense, but I cannot use
apply()
or any of the other options to get a readable string value on the
password.result
output. What am I missing here? Is there some sort of async/await functionality I can use to wait for it to resolve? Thanks!
b

billowy-army-68599

07/22/2022, 7:07 PM
@big-notebook-65054 you can’t convert an output to a string. see https://leebriggs.co.uk/blog/2021/05/09/pulumi-apply for a more in depth review You’ll need to define the userdata inside an
apply
block. If you tell me which language you’re using and share some of your code I can create an example
b

big-notebook-65054

07/22/2022, 8:56 PM
Aha, thank you for that link. So something like this should work:
Trying it now. Will let you know how it goes
Looks like that worked! Thanks for you help
❤️ 1
13 Views