https://pulumi.com logo
#golang
Title
# golang
k

kind-minister-39119

04/14/2020, 6:39 PM
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

broad-dog-22463

04/14/2020, 6:41 PM
@lemon-agent-27707?
g

green-morning-1318

04/14/2020, 6:56 PM
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

kind-minister-39119

04/14/2020, 6:56 PM
ohhhhhh
thank you!
g

green-morning-1318

04/14/2020, 6:57 PM
no problem 🙂 we’re all here to help each other
l

lemon-agent-27707

04/14/2020, 7:03 PM
@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

kind-minister-39119

04/14/2020, 7:05 PM
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

lemon-agent-27707

04/14/2020, 7:08 PM
Copy code
ctx.Export("key", outputValue)
Then via the CLI you can do:
Copy code
$pulumi stack output key
"plain string value returned"
k

kind-minister-39119

04/14/2020, 7:09 PM
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

lemon-agent-27707

04/14/2020, 7:09 PM
You can shell out to call that CLI command and get the value.
k

kind-minister-39119

04/14/2020, 7:10 PM
oh boy
okay
l

lemon-agent-27707

04/14/2020, 7:10 PM
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

kind-minister-39119

04/14/2020, 7:10 PM
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

lemon-agent-27707

04/14/2020, 7:11 PM
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

kind-minister-39119

04/14/2020, 7:12 PM
Okay. This gives me the information I need. Thank you 🙂
👍 1
l

lemon-agent-27707

04/14/2020, 7:12 PM
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

kind-minister-39119

04/14/2020, 7:14 PM
Thanks. Do any of the other languages have runtime API support?
l

lemon-agent-27707

04/14/2020, 7:15 PM
Not today.
k

kind-minister-39119

04/14/2020, 7:15 PM
thanks
3 Views