Question getting the actual value after using get_...
# python
c
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
you’re doing the
apply
in the wrong place
Copy code
stack = pulumi.StackReference(aca_stack_ref)
default_domain = stack.get_output("default_domain")

default_domain.apply(
  lambda domain: domain.split(".")
c
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
you need to be inside the apply
this will never work
Copy code
default_domain_arr = default_domain.apply(lambda domain: domain.split("."))
You have to do what you’re trying to do inside the apply
c
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
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
Roger that, many thanks 🙌
a
@billowy-army-68599 Wouldn't we be able to do this using the new
StackReference.get_output_details()
method?
b
yep, that wasn’t shipped when we had this convo 😄
c
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
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
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