What's the best way to fetch a few stack outputs w...
# getting-started
m
What's the best way to fetch a few stack outputs when I start my local frontend development server? • It would be easy if Pulumi let me get stack refs / outputs outside a Pulumi program, but this doesn't seem possible • I also explored using the automation API, but I don't want to (a) create a new stack just to read other stack's outputs (since multiple developers would have their own "local read" stack which seems messy), and I don't think I can (b) get the existing Pulumi programs using the automation API (since they are defined elsewhere) Am I missing something here? I just want to read my backend's API endpoint from a given stack, but not during another Pulumi program. Alternatively, if there's a better way to use some ephemeral "local stack" to run my dev server (that doesn't end up in Pulumi's state management) that I'm missing, let me know. Thanks!
It turns out (b) is possible (see https://archive.pulumi.com/t/5031454/is-there-a-way-to-get-the-outputs-of-another-stack-in-the-au). As mentioned in the linked discussion, not the cleanest, but it works.
a
Have you looked at Pulumi ESC? It supports fetching stack outputs (and many other things) and exposing them temporarily (default lifetime 2h), f.x. in a local dev environment. To initialize:
esc env init your-org/your-project/your-environment
To edit the environment (you can also do this in the Pulumi Cloud UI)
esc env edit your-org/your-project/your-environment
Example configuration which fetches some stack outputs and exposes them as env vars:
Copy code
values:
  stackRefs:
    fn::open::pulumi-stacks:
      stacks:
        networkProd:
          stack: networking/prod
  environmentVariables:
    ENVIRONMENT: ${stackRefs.networkProd.env}
    SOME_OTHER_VAR: ${stackRefs.networkProd.some_other_output}
Then depending on how you'd like to consume the outputs: In an
.envrc
file - see full example
Copy code
eval $(esc open <your-project-name>/<your-environment-name> --format shell)
Passing env vars directly to a program via esc run:
Copy code
esc run orbit/networking/output-test -- bash -c 'echo $ENVIRONMENT'
Or via docker
env_file
parameter - see example
m
Sorry, I must have missed this reply earlier. Thank you for making me aware of this! I'll need to do some more reading to figure out if this will meet my needs, but it looks promising. I've yet to take the plunge and figure out how to use ESC, but it seems to keep cropping up as the solution to many of my problems :)