https://pulumi.com logo
#general
Title
# general
m

modern-toothbrush-56347

08/05/2021, 12:20 PM
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

brave-planet-10645

08/05/2021, 1:04 PM
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

modern-toothbrush-56347

08/05/2021, 4:10 PM
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

little-cartoon-10569

08/05/2021, 8:36 PM
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

bored-oyster-3147

08/05/2021, 8:48 PM
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

modern-toothbrush-56347

08/06/2021, 9:10 AM
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

little-cartoon-10569

08/08/2021, 9:24 PM
Apply returns an output, but the real value is available inside the Apply.
2 Views