From d63c3703e3075371ef3ae33a2c9fb2c93ff16fc2 Mon Sep 17 00:00:00 2001 From: Luke Amdor Date: Fri, 20 Oct 2017 08:07:59 -0500 Subject: [PATCH] only use the default subscription if not set explicitly --- azurerm/provider.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/azurerm/provider.go b/azurerm/provider.go index c159bc32029f..c04d50ed2dc7 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -253,13 +253,15 @@ func (c *Config) LoadTokensFromAzureCLI() error { return fmt.Errorf("Azure CLI Authorization Profile was not found. Please ensure the Azure CLI is installed and then log-in with `az login`.") } - // pull out the TenantID and Subscription ID from the Azure Profile - for _, subscription := range profile.Subscriptions { - if subscription.IsDefault { - c.SubscriptionID = subscription.ID - c.TenantID = subscription.TenantID - c.Environment = normalizeEnvironmentName(subscription.EnvironmentName) - break + // pull out the TenantID and Subscription ID from the Azure Profile, if not set + if c.SubscriptionID == "" && c.TenantID == "" { + for _, subscription := range profile.Subscriptions { + if subscription.IsDefault { + c.SubscriptionID = subscription.ID + c.TenantID = subscription.TenantID + c.Environment = normalizeEnvironmentName(subscription.EnvironmentName) + break + } } }