I am really struggling with understanding how outp...
# typescript
I am really struggling with understanding how outputs work in Pulumi. Here's what I'm trying to do. After creating an alb loadbalancer with
new aws.alb.loadbalancer
I'm trying to use an output in a userdata script:
const test = "test"
const dnsName = lb.dnsName
const userData =
echo Test string: ${test}
`echo ${dnsName}``
The diagnostic log produces:
echo Test string: test
echo Calling [toString] on an [Output<T>] is not supported.
To get the value of an Output<T> as an Output<string> consider either:
`1: o.apply(v =>
)` `2: pulumi.interpolate `prefix${v}suffix``
See <https://pulumi.io/help/outputs> for more details.
This function may throw in a future version of @pulumi/pulumi.
I've been through the output documentation in the URL in addition to combing this Slack workspace but I can't seem to find a solution here. How can I use the dnsName output from the lb resource as a pure string?
As the note pinned to the channel mentions - the answer is basically always to use apply :-). In this case you can/should use both the suggestions: 1.
userData = pulumi.interpolate
...`` 2.
userData.apply(d => console.log(d))
The key is that because one of your inputs is an “output”, your user data will also need to be an “output”.
❤️ 1
It finally clicked. I was so intent on being able to see the string from a log statement that I was attempting to use apply on the original output, not the variable I wanted the output to appear in. Thank you again for your help. Just for feedback, I think it would help a lot of new users if you included a functional example using cloud resources on the outputs help page.