Pulumi C#: access stackname before RunAsync

Viewed 405

Is there a way with Pulumi to access the current stack name in order to chose which class to run when doing pulumi up?

I want to do something like that:

static Task<int> Main()
{
    if (Deployment.Instance.StackName.StartsWith("local-"))
        return Deployment.RunAsync<LocalStack>();

    return Deployment.RunAsync<AzureStack>();
}
1 Answers

Deployment.Instance is not available before you execute RunAsync, which you already figured out.

As a workaround, you could get the stack name from the environment variable:

Environment.GetEnvironmentVariable("PULUMI_STACK")

Related