How can I change Output<String> to string in...
# general
r
How can I change Output<String> to string in C#?
e
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
@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
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
@echoing-dinner-19531 I keep running into this issue
@echoing-dinner-19531 I keep running into this problem
e
The result of Output.Apply is another Output. It's like how Task.ContinueWith returns another Task.
r
@echoing-dinner-19531 So there is no option to just get the string from that task?
e
No because in general that string might not exist
How could we return a string for a resource output at preview time?
r
@echoing-dinner-19531 But cant I just check if the string exists?
Guess I need to hard code the string then 🙂
e
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
@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
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
@echoing-dinner-19531 That makes sense I have done that before