https://pulumi.com logo
#getting-started
Title
# getting-started
s

stale-iron-26898

06/20/2022, 4:13 PM
Hi all, I have simple use-case but it become harder 😞 I use RandomPassword to generate password and save it into variable
user_password = RandomPassword().result
the variable ‘user_password’ I sent to my dynamic resource which only create a query with the ‘user_password’ inside (Eventually is a string ) the problem is that the value is the Object itself
<pulumi.output.Output at 0x7ffe81ffe6d0>
is there a way to export the value i get from randomPassword into a string in run time? 😢 Thanks!
l

little-cartoon-10569

06/20/2022, 9:01 PM
There is, but you probably shouldn't use it. You can use the
apply()
method on the output, which takes a function as a parameter, and the password value will be available inside that function (but not at the top level).
However, this is rarely necessary. Can you explain or show in code how you want to use this password? Generally, you can pass the output value into other Pulumi resources, and let them handle the extraction of the string from the output.
s

stale-iron-26898

06/21/2022, 10:50 AM
Hi @little-cartoon-10569, I want to use a random password resource with pulumi and send it as string to other function that should read this and put in file I tried to use with apply but unfortunately none of the tries succeed. do you able to solve any kind of this similar issue?
l

little-cartoon-10569

06/21/2022, 7:47 PM
You cannot pass it as a string to another function, except from within an apply. And ideally you should not do that. What sort of function takes the password parameter? If it is a Pulumi constructor, you don't need a string, the output will do fine. If it is anything else, you should either change it (to be a Pulumi constructor), or use an apply. There are many examples of using apply, in the documentation and in the examples repo (https://github.com/Pulumi/examples).
4 Views