https://pulumi.com logo
#dotnet
Title
# dotnet
a

abundant-knife-92318

09/19/2023, 2:33 PM
I'm having some issues getting Pulumi to read Environment Variables. Specifically I want to use the
ARM_
environment variables to configure the Azure Native provider to use a Service Principal. I'm doing a quick and dirty check before my Program runs to check that the environment variables are all set...
Copy code
foreach (DictionaryEntry e in Environment.GetEnvironmentVariables())
    {
        if (e.Key.ToString()!.StartsWith("ARM")) Console.WriteLine(e.Key + ":" + e.Value);
    }
And this returns exactly what I would expect to see...
Copy code
ARM_CLIENT_ID:xxxxxxxxxxxxxxxxx
ARM_TENANT_ID:xxxxxxxxxxxxxxxxx
ARM_CLIENT_SECRET:xxxxxxxxxxxxxxxxx
ARM_SUBSCRIPTION_ID:xxxxxxxxxxxxxxxxx
Yet when the Program runs it is still trying to use the Azure CLI:
Copy code
error: obtain subscription() from Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: No subscription found. Run 'az account set' to select a subscription.
Am I missing something?
b

billowy-army-68599

09/19/2023, 2:45 PM
are you passing those env vars to a provider?
a

abundant-knife-92318

09/19/2023, 9:07 PM
Hey @billowy-army-68599 - thanks for responding! Not in this instance - my assumption was that the Provider would look for the presence of the environment variables in the same way it detects the authentication context of the az CLI? When I did try passing the parameters into the Azure Provider manually...
Copy code
Provider = new Provider("azure-provider", new ProviderArgs()
        {
            Environment = "public",
            ClientId = AppConfig.GetValue<string>("ARM_CLIENT_ID"),
            ClientSecret = AppConfig.GetValue<string>("ARM_CLIENT_SECRET"),
            TenantId = AppConfig.GetValue<string>("ARM_TENANT_ID"),
            SubscriptionId = AppConfig.GetValue<string>("ARM_SUBSCRIPTION_ID")
        });
...I got an error stating that location had not been set...
Copy code
azure-native:resources:ResourceGroup resource 'rg-dev-sta-marketplace-eus-001' has a problem: missing required property 'location'. Either set it explicitly or configure it with 'pulumi config set azure-native:location <value>'.
but there is no Location property on the Provider, and I have already set the
azure-native:location
in my stack config.
I've been digging around, but still struggling to work out what is going on here =/
I'm not keen to encrypt these credentials into the Pulumi config because it seems to be quite easy to extract them at runtime
2 Views