Hey team, I am new to Pulumi and I am stuck on one...
# general
e
Hey team, I am new to Pulumi and I am stuck on one usecase where I want to show the user the actual property value in my stack trace. My current stack output is this:
Copy code
Current stack outputs (1):
                              OUTPUT  VALUE
                                               vid     vpc-0515230c3d5f949a8
I am able to reference my stack using
stack_ref = pulumi.StackReference("PulumiPlay-dev")
but I am not sure how to print the value of vid now. I have tried using the
get_output
method but it is not returning anything.
e
stack_ref.get_output("vid") should return it
s
Or if you want the value from the command line:
pulumi stack output vid
e
I followed the automation API tutorial: https://github.com/pulumi/automation-api-examples/blob/main/python/inline_program/main.py In a different python file I am running this code:
Copy code
import pulumi

stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: "https://" + s3_url
)}
print(obj)
The output that I am getting still shows me the object and not the value:
Copy code
{'website_url': <pulumi.output.Output object at 0x109f9f2b0>}
e
Oh that's because
apply
always returns an Output object. If you did that print inside the apply function it would print the string value
Also
Output.format("https://{0}", stack_ref.get_output("website_url"))
is probably a nicer way to do this rather than an apply
e
I tried running this too. This is just giving me an empty response.
Copy code
import pulumi

stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: f"https:// + {print(s3_url)}"
)}
Print is not working for me.
e
That's not how print is meant to work:
Copy code
stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: f"https:// + {s3_url}"
)}
obj["website_url"].apply(lambda s: print(s))
I'd expect that to print out the url