https://pulumi.com logo
Title
e

echoing-activity-32278

02/04/2023, 3:27 PM
How can I get a string value?
def example():
   stack = StackReference(f"some-stack")
   # of course this fails
   string_value = stack.require_output("some-output")
o

orange-policeman-59119

02/04/2023, 4:08 PM
For now you must use Apply (which will yield an Output[str]), but you can follow this issue for updates on getting plain, non-output values: https://github.com/pulumi/pulumi/issues/10839
e

echoing-activity-32278

02/04/2023, 4:19 PM
I think the worst case is I spawn a new process to call “pulumi stack output some-output” directly and parse the result. Before going to this, any other approaches?
o

orange-policeman-59119

02/04/2023, 4:21 PM
There is almost always a way to do what you want using apply, so I'd be surprised if your use case wasn't handled. If you want to print out the string, put the print in an apply. Make an http request with it? In an apply. All resources accept Outputs for their args.
The reason we do this is to protect secrets and track dependencies. We're evaluating whether we should allow an escape hatch to "await" an output directly, but if misused it can cause secret values to leak or certain operations to fail, especially replacements and destroys.
e

echoing-dinner-19531

02/04/2023, 5:28 PM
This'll probably be in the next release (or at least the one after that). We're adding new get methods that return a tuple of { value: string, secretValue: string }, so you always get a plain value but you need to check if it's secret or not yourself and handle that.
e

echoing-activity-32278

02/05/2023, 12:59 AM
@echoing-dinner-19531 Possible to inform me some internal function that I can hack it now. I don’t care about stability.
e

echoing-dinner-19531

02/05/2023, 9:25 AM
This is python so there is an undocumented function on Output,
o.future()
returns an
Awaitable[T]
Will work fine for this because stack refs are always known, but it can return None for some outputs. And clearly you lose tracking of any secret bit or dependencies.
e

echoing-activity-32278

02/05/2023, 2:23 PM
For this simple code
from pulumi import StackReference
import asyncio

async def main():
    stack = StackReference(f"some-stack")
    fut = stack.require_output("some-output").future()
    ret = await fut


asyncio.run(main())
It fails claiming some errors like
attached to a different loop
e

echoing-dinner-19531

02/05/2023, 7:38 PM
I do not know asyncio well enough to suggest much here, but that is all that StackReference is doing internally.