https://pulumi.com logo
Title
r

refined-printer-32244

11/13/2022, 11:23 PM
hey! i'm using pulumi for some personal things to get a handle on it and I'm having a heck of a time in Go from converting various
Output
values to concrete values. everything I find online seems to call methods that don't exist for me or don't seem to work as the stuff I find online says. currently, I have an output named
projectName
on one stack, and I use a stack reference to get that value from from the other stack as a
pulumi.AnyOutput
and then use that with
.AsStringOutput()
to give me a
pulumi.StringOutput
(it's a string, this seems to work fine). however, i'm trying to take that value and pass it into a
digitalocean.LookupProject
where the
Name
arg expects
*string
. I've tried a bunch of iterations, including
ApplyT
with a
func(projName string) *string
, but I just can't seem to get the value the lookup expects. I'm also having a hard time taking
pulumi.StringOutput
to
string
at times as well. it sounds like it's supposed to be
ApplyT
, but that just returns an output that gets me back into the same
pulumi.StringOutput
. anyone have some tips for me?
l

little-cartoon-10569

11/13/2022, 11:25 PM
Anything with "Output" in its type is not available now, only in the future. You either need to wait for it, or use it in a callback that gets called later, when it's available.
The basic documentation is at https://www.pulumi.com/docs/intro/concepts/inputs-outputs/. Look for
ApplyT()
.
r

refined-printer-32244

11/13/2022, 11:34 PM
that's the part i'm having trouble with =/ the docs say it's supposed to support "lifting" but the only example it gives is pulling some element from an array, but that same idea doesn't seem to work with getting a
string
from a
pulumi.StringOutput
as far as i can tell there's nothing on this that will return a
string
https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi#StringOutput, and the inner
*OutputState
only seems to include
ApplyT
, which just returns another
pulumi.Output
.
l

little-cartoon-10569

11/13/2022, 11:45 PM
Yes, the string is not available yet, you cannot get at it.
r

refined-printer-32244

11/13/2022, 11:49 PM
there has to be some way for me to get it, though. otherwise I could never use an output as a lookup for a resource, right?
l

little-cartoon-10569

11/13/2022, 11:50 PM
Did you read the link I posted above, and the code snippet with ApplyT()?
You put your code inside that callback. The callback is called later, when the value is available
r

refined-printer-32244

11/13/2022, 11:51 PM
yeah, that's what i've been trying
l

little-cartoon-10569

11/13/2022, 11:51 PM
⬅️ Post your code. Use the "Create a text snippet" function in Slack's "+" menu.
r

refined-printer-32244

11/13/2022, 11:55 PM
I've tried a lot of iterations of trying to get a value for
Name
, which requires a
*string
.
ahh, i think i got it. i need to use
digitalocean.LookupProjectOutput
which will accept and return input/output types
l

little-cartoon-10569

11/14/2022, 12:07 AM
Ah, if there's an Output version of a parameter, that definitely helps!
r

refined-printer-32244

11/14/2022, 12:08 AM
yup! i'd definitely like to figure out this problem I'm having at some point, though. the way things are explained it sounds like what I've been doing should work, but it's not. so it makes me feel like the go code is some weird edge case
l

little-cartoon-10569

11/14/2022, 12:09 AM
For the ApplyT() in that code you posted: you should need the ApplyT() in this case. Because the Name parameter should take an output, you don't need to convert the name output. You should be able to use it directly. It does look like everything's good...
r

refined-printer-32244

11/14/2022, 12:09 AM
yeah, if i get rid of the
ApplyT
on there it'll complain that it can't assign
pulumi.StringOutput
or
pulumi.StringPtrOutput
(I tried both) to a
*string
l

little-cartoon-10569

11/14/2022, 12:13 AM
But nothing in there is a string, is it?
Name
should be an Input, and
projName
is an Output. I guess my golang is not up to this problem.. I should stick with typescript...
r

refined-printer-32244

11/14/2022, 12:15 AM
i do feel like it's some weirdness with the go type system. there are
pulumi.Output
values, but those are subdivided into
pulumi.StringOutput
, etc. and then if I try to convert a
pulumi.StringOutput
to a
string
by just doing something like
var myString string = myStringOutput
it sounds like that should work, but it doesn't
l

little-cartoon-10569

11/14/2022, 12:33 AM
No, that won't ever work. The StringOutput isn't yet known, it's a promise / future. You cannot convert it to a string.
You can get your code to be called later, when the value is known. That's the best you can do.
r

refined-printer-32244

11/14/2022, 12:38 AM
yeah, that's what i meant. like somehow make it block and return a
string
i think this update to use the lookup outputs is way better, so I don't know if I'll ever want that now though 😄
b

billowy-army-68599

11/14/2022, 1:38 AM
just doing something like
var myString string = myStringOutput
it sounds like that should work, but it doesn’t
yeah that unfortunately won’t ever work. You can’t assign an
StringOutput
to a
string
unless you are inside the
ApplyT
. so as an example:
// here myOutputValue is always an output
myOutputValueApplyT(func(myOutput string) string {
  // here, we are inside the ApplyT function, so we have resolved the value and now it's a string
  fmt.Println(myOutput)
}