Hi! I am trying to read a stack reference and get ...
# dotnet
Hi! I am trying to read a stack reference and get the value of some of the stack outputs in my C# console application. In powershell, I can do: $stackOuputs = pulumi stack output --show-secrets -s "myorg/mystack/dev" So I assumed I would be able to do the following in C#: var stackReference = new StackReference("myorg/mystack/dev"); var stackOutput = await stackReference.GetValueAsync("OutputName"); But it does not look like StackReference is supported outside of Run: 'Trying to acquire Deployment.Instance before 'Run' was called.' So any ideas on how to read a Stack outputs in a non-pulumi program using the C# SDK?
you can’t use the Pulumi SDK outside of a Pulumi program. you need to use the automation API in order to do that
Thanks @billowy-army-68599 ! Such speed! Any pointers / sample code already out there?
https://github.com/pulumi/automation-api-examples/tree/main/dotnet you may just find it easier to run
pulumi stack output --show-secrets -s "myorg/mystack/dev"
as an executable in your program if you only need to get the stack reference
@billowy-army-68599 thanks! It does not look like 'pulumi login' is supported by the automation api right? Is there a way to auth with an access token without relying on the pulumi cli?
pulumi login
just builds a
like this
Copy code
  "current": "<https://api.pulumi.com>",
  "accessTokens": {
    "<https://api.pulumi.com>": <redacted>
  "accounts": {
    "<https://api.pulumi.com>": {
      "accessToken": <redacted>,
      "username": "jaxxstorm",
      "organizations": [
      "lastValidatedAt": "2022-07-12T17:32:23.907266-07:00"
You can just create that file and write it yourself 🙂
👍 1
you will need the pulumi cli for most operations though, it’s the on;y effective way to talk to the engine
Sweet, thanks a lot. Yes I used the Pulumi cli a lot for deploying the infrastructure. Now putting together a lightweight app for a tech to provision that infrastructure, trying to keep the dependencies/extra steps as little as possible
if you’re not using the automation API, it’s going to make your life much much easier 😄