Hi, quick question: How do you use an output as a ...
# general
m
Hi, quick question: How do you use an output as a string? e.g. I create a VM, and one of its outputs is its Public IP address (or DNS name). I then want to load an XML file and insert the Public IP into the file and use that in the next step. I can't do this because XML manipulation (or even search/replace) operations require strings and an Output is not a string. Any ideas?
b
Take a look at this section in our docs: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#outputs-and-strings there's some good information there that should help you
m
Thanks Piers, I can see how to use Output.Format(), but I'm not sure how I would, for example, load a string from a file and then format it. The parameter to Output.Format is a "FormattableString" and won't accept a plain string by the look of it.
l
If you have a string you don't need to deal with Output. Keep it as a string.
Outputs are futures, you cannot get at their values yet, so working with them takes some getting used to. If you can avoid using them (such as when loading values from a file right now), then do.
b
Since you want to interpolate your XML with the outputted IP address: when you have both the IP address output and the XML loaded as a string, do
ipAddress.apply(ip => do interpolation here);
which will give you your interpolated result as an output.
m
Thanks Joshua, That works for me. I couldn't work out how to do that with "Apply" before: I always thought it would just give me another "output" variable again, but, as you say, the "ip" parameter passed to the lamba is indeed a "normal" string so I can do what I need in there. Thanks for the help
👍 1
l
Apply returns an output, but the real value is available inside the Apply.