From 44829f2621da31096fe4b06d3ca810631dc078b2 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Fri, 12 Jun 2020 19:02:17 +0100 Subject: [PATCH] Stop requiring subscription ID to be configured for the provider Configuring a subscription ID is a vestige from the provider split. We don't use subscription_id anywhere and have no plans to. Any resource that operates on a subscription or its dependents should belong in the azurerm provider. Although it's never used because we only use SDK clients that are configured with a tenant ID, go-azure-helper requires it for sensible reasons and it doesn't make sense to push this concern upstream for now. We'll keep the configuration property around for now so that users have time to remove it from their configurations. --- azuread/config.go | 2 -- azuread/provider.go | 13 ++++++++----- azuread/provider_test.go | 1 - 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/azuread/config.go b/azuread/config.go index 93b2b59eb9..aea3c2ab5b 100644 --- a/azuread/config.go +++ b/azuread/config.go @@ -19,7 +19,6 @@ import ( // ArmClient contains the handles to all the specific Azure ADger resource classes' respective clients. type ArmClient struct { - subscriptionID string clientID string objectID string tenantID string @@ -57,7 +56,6 @@ func getArmClient(authCfg *authentication.Config, tfVersion string, ctx context. // client declarations: client := ArmClient{ - subscriptionID: authCfg.SubscriptionID, clientID: authCfg.ClientID, objectID: objectID, tenantID: authCfg.TenantID, diff --git a/azuread/provider.go b/azuread/provider.go index 37d7d5572a..4e68aa87b2 100644 --- a/azuread/provider.go +++ b/azuread/provider.go @@ -12,10 +12,11 @@ import ( func Provider() terraform.ResourceProvider { p := &schema.Provider{ Schema: map[string]*schema.Schema{ + // TODO: remove subscription_id field at next major version "subscription_id": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("ARM_SUBSCRIPTION_ID", ""), + Type: schema.TypeString, + Optional: true, + Default: "", }, "client_id": { @@ -100,11 +101,13 @@ func Provider() terraform.ResourceProvider { func providerConfigure(p *schema.Provider) schema.ConfigureFunc { return func(d *schema.ResourceData) (interface{}, error) { + // When constructing the Builder, we use the tenant ID for the subscription ID. + // Although this has no effect since we never consume it, this practise mimics + // the Azure CLI and it seems the most sensible value to use after a nonsense string. builder := &authentication.Builder{ - // TODO: remove the requirement on the Subscription ID - SubscriptionID: d.Get("subscription_id").(string), ClientID: d.Get("client_id").(string), ClientSecret: d.Get("client_secret").(string), + SubscriptionID: d.Get("tenant_id").(string), TenantID: d.Get("tenant_id").(string), Environment: d.Get("environment").(string), MsiEndpoint: d.Get("msi_endpoint").(string), diff --git a/azuread/provider_test.go b/azuread/provider_test.go index 04264f369b..627a374397 100644 --- a/azuread/provider_test.go +++ b/azuread/provider_test.go @@ -32,7 +32,6 @@ func TestProvider_impl(t *testing.T) { func testAccPreCheck(t *testing.T) { variables := []string{ - "ARM_SUBSCRIPTION_ID", "ARM_CLIENT_ID", "ARM_CLIENT_SECRET", "ARM_TENANT_ID",