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

careful-market-30508

02/13/2020, 7:19 PM
Once I export a variable like : pulumi.export("NodeName", node) . (btw node is of type pulumi.Output I guess). How do I access it and print it ? print(NodeName) doesnt work.
w

white-balloon-205

02/13/2020, 7:52 PM
The goal of
pulumi.export
is to make it available outside of Pulumi. You can
pulumi stack output
to get all outputs or
pulumi stack output NodeName
to get just that one. From within the program, you can print an output with:
node.apply(lambda n: print(n))
or just
node.apply(print)
Note that those will only print the value once it is available.
c

careful-market-30508

02/13/2020, 7:58 PM
how do i get it into a variable?
w

white-balloon-205

02/13/2020, 8:00 PM
You get the value within the function passed to apply. You can write a
def myfunc(n):
and then write code within that function that does whatever you want, and call
node.apply(myfunc)
. See https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs for much more detail on this.
c

careful-market-30508

02/13/2020, 8:07 PM
Copy code
h = str
def myfunc(n):
    h = n

node.apply(myfunc)

print ( "h = {}".format(h))  # prints  h = <class 'str'>
w

white-balloon-205

02/13/2020, 8:09 PM
The equivalent of what you are trying to do there in Pulumi would be:
Copy code
def myfunc(n):
    print ( "n = {}".format(n)) 
node.apply(myfunc)
If your real example is something different than this - please share it and I can suggest how to structure in Pulumi.