https://pulumi.com logo
Title
c

calm-doctor-76791

04/05/2023, 8:02 PM
Question getting the actual value after using get_output, what is the preferred way? I´ve tried the following snippet, using apply on the output, which does not seem to work;
stack = pulumi.StackReference(aca_stack_ref)
default_domain = stack.get_output("default_domain").apply(lambda x: x)
default_domain_arr = default_domain.split(".")
....
Which returns the following when ran; default_domain_arr = default_domain.split(".") ^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'Output' object is not callable
b

billowy-army-68599

04/05/2023, 8:10 PM
you’re doing the
apply
in the wrong place
stack = pulumi.StackReference(aca_stack_ref)
default_domain = stack.get_output("default_domain")

default_domain.apply(
  lambda domain: domain.split(".")
c

calm-doctor-76791

04/05/2023, 8:22 PM
Many thanks, how could I get the splitted output as an array?
stack = pulumi.StackReference(aca_stack_ref)
default_domain = stack.get_output("default_domain")
default_domain_arr = default_domain.apply(lambda domain: domain.split("."))
lb_resource_group_name = f"mc_{default_domain_arr[0]}-rg_{default_domain_arr[0]}_{default_domain_arr[1]}"
b

billowy-army-68599

04/05/2023, 8:31 PM
you need to be inside the apply
this will never work
default_domain_arr = default_domain.apply(lambda domain: domain.split("."))
You have to do what you’re trying to do inside the apply
c

calm-doctor-76791

04/05/2023, 8:34 PM
Isn´t there a way where I can "grab" the output and place it into a "regular" variable, and continue to work with it as a variable?
b

billowy-army-68599

04/05/2023, 8:38 PM
no, that’s not how Pulumi’s async mechanism works. When you invoke
pulumi up
any output isn’t a known value, so the python interpreter doesn’t know how to handle it. That’s why we have
apply
- that’s our way of saying “this unknown value is known inside the apply so you can use it like a regular string, python”
c

calm-doctor-76791

04/05/2023, 8:39 PM
Roger that, many thanks 🙌
a

ambitious-father-68746

04/06/2023, 4:01 PM
@billowy-army-68599 Wouldn't we be able to do this using the new
StackReference.get_output_details()
method?
b

billowy-army-68599

04/06/2023, 4:22 PM
yep, that wasn’t shipped when we had this convo 😄
c

calm-doctor-76791

04/08/2023, 11:36 AM
Can StackReference.get_output_details() be used? When I read up on it, it seemd like there was some missing Async functionality in the Pulumi/Python provider ( or something in those lines), so that the functionality was not ready for Python yet.
a

ambitious-father-68746

04/08/2023, 5:23 PM
It can be used, I just tried it yesterday and it worked, but it's not straightforward. Having said that, it's easy once you know. Just search for get_output_details here on Slack and there's a thread where someone posted a piece of code that works
c

calm-doctor-76791

04/10/2023, 1:42 PM
Many thanks, using this worked like a charm:
# config.py
def get_output_details(stack, name):
from pulumi.runtime.sync_await import _sync_await
d = _sync_await(
stack.get_output_details(name)
)
return d.value if d.value is not None else d.secret_value