https://pulumi.com logo
Title
r

red-scooter-62880

07/27/2022, 9:01 AM
How can I change Output<String> to string in C#?
e

echoing-dinner-19531

07/27/2022, 11:43 AM
You can't. The most you can do is call
.Apply
and within the apply callback use the string, but keep in mind that callback may not always run at preview time (we might not know what the value of the output is at preview time)
r

red-scooter-62880

07/27/2022, 2:32 PM
@echoing-dinner-19531 Thanks. Can you share code example for how to get the string from within the Apply callback? I am unsure of how to do this 🙂
e

echoing-dinner-19531

07/27/2022, 2:46 PM
There's an example in the docs https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply Apply takes a function delegate and passes the value of the Output<string> as the parameter to that delegate. But keep in mind that Applys run asynchronously and may not even run during preview.
r

red-scooter-62880

07/27/2022, 3:00 PM
@echoing-dinner-19531 I keep running into this issue
@echoing-dinner-19531 I keep running into this problem
e

echoing-dinner-19531

07/27/2022, 3:01 PM
The result of Output.Apply is another Output. It's like how Task.ContinueWith returns another Task.
r

red-scooter-62880

07/27/2022, 3:02 PM
@echoing-dinner-19531 So there is no option to just get the string from that task?
e

echoing-dinner-19531

07/27/2022, 3:02 PM
No because in general that string might not exist
How could we return a string for a resource output at preview time?
r

red-scooter-62880

07/27/2022, 3:02 PM
@echoing-dinner-19531 But cant I just check if the string exists?
Guess I need to hard code the string then 🙂
e

echoing-dinner-19531

07/27/2022, 3:04 PM
Yeh generally you want to avoid using outputs to make fixed strings, again there's some things we're thinking about to make this stuff easier but its a bit long off still
r

red-scooter-62880

07/27/2022, 3:05 PM
@echoing-dinner-19531 Thanks for the explanation 🙂
@echoing-dinner-19531 Are outputs only supposed to be shown in the CLI output, not used in code?
e

echoing-dinner-19531

07/27/2022, 3:06 PM
Oh no you can use them in code, all resource inputs can be Outputs because our code can handle that at preview time an input might be unknown.
So it's quite common to like take an ID from one resource and use that to build another resource.
r

red-scooter-62880

07/27/2022, 3:08 PM
@echoing-dinner-19531 That makes sense I have done that before