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

worried-engineer-33884

11/04/2019, 7:13 PM
Is there a way to get a stack export from the pulumi backend over an api call? (vs using the cli)
c

colossal-beach-47527

11/04/2019, 7:26 PM
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

worried-engineer-33884

11/04/2019, 7:26 PM
Cool! Thanks! cc @dazzling-memory-8548
c

colossal-beach-47527

11/04/2019, 7:27 PM
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

witty-yacht-82771

11/05/2019, 12:52 PM
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

worried-engineer-33884

11/05/2019, 12:56 PM
I usually do:
Copy code
pulumi stack export > my-stack.json
w

witty-yacht-82771

11/05/2019, 1:09 PM
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

colossal-beach-47527

11/05/2019, 4:33 PM
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

witty-yacht-82771

11/05/2019, 4:34 PM
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

colossal-beach-47527

11/06/2019, 12:16 AM
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.