Hi! I am trying to read a stack reference and get ...
# dotnet
f
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?
b
you can’t use the Pulumi SDK outside of a Pulumi program. you need to use the automation API in order to do that
f
Thanks @billowy-army-68599 ! Such speed! Any pointers / sample code already out there?
b
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
f
@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?
b
pulumi login
just builds a
~/.pulumi/credentials.json
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": [
        "jaxxstorm",
        "lbrlabs",
        "team-ce",
        "demo",
        "pulumi"
      ],
      "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
f
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
b
if you’re not using the automation API, it’s going to make your life much much easier 😄