Hi guys, I’m trying to use `StackReference` and pr...
# python
a
Hi guys, I’m trying to use
StackReference
and print in the following example the
other_output
variable, can anyone share an example?
Copy code
other = StackReference("stg")
other_output = other.get_output("regions")
l
get_output
returns an output (think of it like a future). That output can be passed to other pulumi functions, but if you need to do string manipulation, or print the raw value, you'll have to use
.apply
https://www.pulumi.com/docs/intro/concepts/programming-model/#apply
a
Thanks @lemon-agent-27707 for the response. I’ll explain my situation, I have multiple stacks project, each stack has it’s own regions configurations
Copy code
vpc_network:regions: {
    "europe-west1": "10.2.0.0/16",
    "europe-west3": "10.4.0.0/16",
    "us-central1": "10.6.0.0/16",
    "us-east1": "10.5.0.0/16"
  }
in the beginning of the project run (
pulumi up
) I want to verify there is no collision with any network in the other stacks. I’m trying to create two lists: 1. long list of all the existing stacks networks
Copy code
["10.2.0.0/16", "10.4.0.0/16", "10.6.0.0/16", "10.5.0.0/16", "10.11.0.0/16"]
2. list of current stack networks.
Copy code
["10.1.0.0/16", "10.2.0.0/16"]
then check if there is collision between them. • How do I get all stacks in the project? • How do I get current stack variable? • How do I compare between 2 lists of Pulumi objects? Thanks a lot
l
Have you had a chance to look at this documentation? https://www.pulumi.com/docs/intro/concepts/organizing-stacks-projects/ It gives an overview of using stack references. I don't believe we have an API in the SDKs to list all stacks, but there is a CLI command. You could always shell out and execute this command: https://www.pulumi.com/docs/intro/concepts/stack/#listing-stacks
If you have a stack per region, you may consider having two config values associated with each of your stacks, one for all regions, and one for the current region. Then you could construct a stack reference for each, and use pulumi.all to wait for all of the stack refs to be available: https://www.pulumi.com/docs/intro/concepts/programming-model/#all
a
thanks. is there anyway to convert pulumi object into regular python object?
l
Can you provide some detail on your use case and what you're trying to accomplish? In general you can only access the raw value inside of
.apply
, but you can always pass an output as an input to another resource.