Is there a way to get a stack export from the pulu...
# general
w
Is there a way to get a stack export from the pulumi backend over an api call? (vs using the cli)
c
Yes, we haven’t documented our REST API or published a Swagger spec. But you can use the stack export endpoint yourself by using
curl
. For example:
Copy code
export PULUMI_ACCESS_TOKEN="pul-..."
# Fully-qualified stack name, with organization
# project, and stack name.
export STACK="pulumi/get.pulumi.com/production"
curl -H "Authorization: token ${PULUMI_ACCESS_TOKEN}" \
     <https://api.pulumi.com/api/stacks/$>{STACK}/export
w
Cool! Thanks! cc @dazzling-memory-8548
c
That will return the checkpoint of the latest version of the stack. To get an earlier version (e.g. that deployment from two weeks ago) you can specify a specific “version” (from the Pulumi Service), using:
Copy code
… /api/stacks/${STACK}/export/{version}
👍 1
💯 1
w
Great stuff…stupid followup question: how can I do the same thing from the CLI? (i.e. access stack exports outside of a stack context). I’ve been scouring the docs and can’t find this
w
I usually do:
Copy code
pulumi stack export > my-stack.json
w
Ah, I was thinking in the context of running from a different directory: I have some local tests in a separate project that run against a db deployed from a stack, so it would be ideal to programmatically get the deployed endpoint and inject it to those
I could also reorganize my projects, but was just curious in general about CLI querying arbitrary stack exports
c
I don’t quite follow what you are saying, but you should be able to provide
--stack
and
--cwd
parameters to
pulumi stack export
. So you can in theory export the checkpoint file of another stack you have access to, or perhaps in the context of running
pulumi
from a different directory.
w
yes, that’s exactly what I was (unclearly) asking for, I’ll go play with it now. Thanks!
Oh one more q: is there a similar API endpoint just for stack outputs?
c
Unfortunately no, there isn’t a stack-output specific API endpoint. You’ll need to run the stack export and then search for the output properties of the “stack” resource (there should be exactly one resource with type
pulumi:pulumi:stack
or similar). We’ll probably add something like that when we start documenting the v1.0 of our REST API, but for now that’s the way to get a stack’s outputs.