Ole Albers
Ole Albers

Reputation: 9305

Define Azure-Subscription to be used in Pulumi

I use the following (standard)-Pulumi - Code to create a simple resource:

  public MyStack()
    {

        var current = Output.Create(GetSubscription.InvokeAsync());
        this.CurrentSubscriptionDisplayName = current.Apply(current => current.DisplayName);


        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup("dingdongdiehexisttot");  // TODO: Conf


        // Create an Azure Storage Account
        var storageAccount = new Account("storage", new AccountArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AccountReplicationType = "LRS",
            AccountTier = "Standard"
        });

        // Export the connection string for the storage account
        this.ConnectionString = storageAccount.PrimaryConnectionString;
    }

this fails with a 403 because it is created in a subscription where I am not allowed to create resources into. I have multiple subscriptions and want to define WHICH subscription to be used. I can retrieve the current using "GetSubscription" but did not find any method to actually SET which subscription to use.

How can I define the subscription to be used

(I successfully logged in using az login before runnung pulumi up)

Upvotes: 2

Views: 1494

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

Several options here:

  1. Select your target subscription with the Azure CLI: az account set --subscription SUBSCRIPTION

  2. Use pulumi config set azure:subscriptionId SUBSCRIPTION.

  3. Set the environment variable ARM_SUBSCRIPTION_ID.

  4. Use Explicit Providers and configure it in the provider's properties.

Upvotes: 8

Related Questions