Hi, I’d like to hand off the string value of a `St...
# golang
k
Hi, I’d like to hand off the string value of a
StringOutput
as a
string
— how can I do this conversion? I don’t see any straightforward method.
b
@lemon-agent-27707?
g
Pasting an answer from Evan I got for roughly the same question 😉 these values are essentially futures/promises, you need to use 
pulumi.Apply
 to execute a callback on the raw values. Some docs on this here: https://www.pulumi.com/docs/intro/concepts/programming-model/#apply A common pattern we use if unit testing functionality is to pass the raw values back into channels. There’s an example of that here: https://github.com/pulumi/pulumi/blob/master/sdk/go/pulumi/types_test.go#L320-L349
👍 1
k
ohhhhhh
thank you!
g
no problem 🙂 we’re all here to help each other
l
@kind-minister-39119 happy to take a look at the code you're working on. The general rule of thumb is that any manipulation of output types (transforming, string formatting, etc) needs to happen inside of an apply. You can call apply on a string output, and then pass the new output that is returned on to another resource.
k
I’m not trying to pass it along to any other Pulumi code, I’m writing a layer of abstraction over pulumi to allow our developers to use it without having to think about pulumi’s idiosyncratic types. I have a
EC2Instance
struct which contains an
ec2.Instance
from Pulumi. I want to be able to populate the
EC2Instance
with data from the underlying pulumi resource
Does this
Apply
mechanism allow me to funnel these values out of Pulumi? because right now it seems like there’s an attempt to jail the data
In the example you give, it seems like I would still end up with a
StringOutput
— what I want is a
string
l
Copy code
ctx.Export("key", outputValue)
Then via the CLI you can do:
Copy code
$pulumi stack output key
"plain string value returned"
k
But I’m not allowed to take that data and just use it however I want? The only thing I can do with it is show it to the user?
l
You can shell out to call that CLI command and get the value.
k
oh boy
okay
l
It sounds like what you want is a runtime API: https://github.com/pulumi/pulumi/issues/3901
Feel free to put some thoughts on that issue, definitely something we'd like to look into.
k
A runtime API would be great. But at a minimum, what would let me do what I want to do is a way to get the value of an output in code.
I guess that’s what you’re referring to
nvm
l
You can use the pulumi integration testing framework written in go: https://www.pulumi.com/docs/guides/testing/integration/#pulumi-s-integration-test-framework
k
Okay. This gives me the information I need. Thank you 🙂
👍 1
l
It gives you a programmatic way to create a stack, and run some code that has access to the stack outputs at the end. Perhaps not exactly what you're looking for, but might be helpful in the meantime until a runtime API is available.
k
Thanks. Do any of the other languages have runtime API support?
l
Not today.
k
thanks