red-market-91256
08/03/2023, 6:51 PMdef myfunc():
stack_ref = pulumi.StackReference('myorg/myproject/mystack')
return pulumi.Output.format("{0}", stack_ref.get_output('url'))
print(myfunc())
When I try to run this I get no output and still get the warning:
Calling __str__ on an Output[T] is not supported.
From the docs it says that using format
should be using apply, and hence it should be wait'ed on and I shouldn't have Output[T]
as a return. Any ideas what I'm missing?proud-art-41399
08/03/2023, 7:20 PMformat
and concat
are just wrappers around apply
to create string outputs in an easier and more intuitive way. However, it still creates an Output
that you need to use apply
upon to access the actual value. The helper functions just serve the purpose of preparing the actual value in a form you need, composed of other outputs' values.red-market-91256
08/03/2023, 7:28 PMreturn pulumi.Output.format("{0}", stack_ref.get_output('url')).apply(lambda x: x)
As that produces the same warningproud-art-41399
08/03/2023, 7:31 PMmyfunc
function is just right. But to print the result, you'd have to use something like
o = myfunc()
o.apply(lambda v: print(v))
red-market-91256
08/03/2023, 7:37 PM.apply(lambda v: print("test"))
just to test and it didn't display).
I can't tell if this is because the API is completing before the output is returning. I sort of want to await
this response but not sure the way to do that?