Using Pulumi to read exported values

97 Views Asked by At

I am using python and Pulumi to instanciate a stack. this is them main.py

import pulumi

from pulumi_gcp import pubsub

topic = pubsub.Topic("my-topic")
pulumi.export("topic_name", topic.name)

On the appication code, I would like to get the topic_name, as I need to publish messages on this topic. Is that possible?

1

There are 1 best solutions below

0
epattaro On

I am having a similar issue.

Naturally, we can pass the object within the same script, and access its attribute, if we want to use it on other configurations.

On a different project, its possible to retrieve the stack, and access the output and its attribute (see url)

I am however trying to access it, without retrieving the stack, from within the same project, without success. Example:

-- project
-- _main_.py
-- rds.py
-- securitygroup.py

So, _main_ would import and run functions that respectively define, create, and export such resources.
rds.py however would need to reference the securitygroup.id. Its unclear to me how to do that without passing it directly as an argument, or importing the stack (which seems redundant).

I would image there is something equivalent to: pulumi.get(resource).id, which retrieves the resource from the current stack by default.

But I was unable to find anything as such.