https://pulumi.com logo
#python
Title
# python
c

clean-engineer-75963

10/04/2019, 4:47 PM
Hello. Brand new to Pulumi as of yesterday. I'm trying it out with Python since the Golang support hasn't fully landed yet. Is there a way I can get the value of an Output as a Python primitive? I'm trying to pass one to
base64.b64encode
and it's not working since it's a
pulumi.Output
and not a bytes-like object.
I trying casting it to a string with
str()
and that didn't work.
I also couldn't drop into a pdb debugger to inspect the thing. 😕
n

numerous-easter-93888

10/04/2019, 4:55 PM
This is on a single Stack or are you referencing from another Stack?
If it's within a single Stack you need to use the
.apply()
function on the
pulumi.Output
object. For example:
bastion_ip = bastion.private_ip.apply(lambda foo: '%s/32' % foo)
c

clean-engineer-75963

10/04/2019, 5:01 PM
Thanks, that worked right away.
The docs suggest that the output of
apply
is another
Output
, which is why I hadn't tried it yet: https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs
The result of the call to apply is a new Output whose value is the value returned from the callback, and which includes the dependencies of the original Output.
n

numerous-easter-93888

10/04/2019, 5:07 PM
Yeah, it is not terribly intuitive, but it's an almost direct port from JavaScript
You need to use the Lambda as a callback function in order to access the data you want