From 78598b973fdbb58e5e63167186d88c098c73c081 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 30 Sep 2019 13:50:54 +0100 Subject: [PATCH] provider: Use real Terraform version --- azurerm/config.go | 3 ++- azurerm/internal/common/client_options.go | 13 +++++++------ azurerm/provider.go | 2 +- azurerm/required_resource_providers_test.go | 2 +- .../resource_arm_container_registry_migrate_test.go | 2 +- ...ource_arm_data_lake_store_file_migration_test.go | 2 +- azurerm/resource_arm_storage_blob_migration_test.go | 2 +- ...resource_arm_storage_container_migration_test.go | 2 +- .../resource_arm_storage_queue_migration_test.go | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index 001ecffa95198..76da3695e470e 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -146,7 +146,7 @@ type ArmClient struct { // getArmClient is a helper method which returns a fully instantiated // *ArmClient based on the Config's current settings. -func getArmClient(authConfig *authentication.Config, skipProviderRegistration bool, partnerId string, disableCorrelationRequestID bool) (*ArmClient, error) { +func getArmClient(authConfig *authentication.Config, skipProviderRegistration bool, tfVersion, partnerId string, disableCorrelationRequestID bool) (*ArmClient, error) { env, err := authentication.DetermineEnvironment(authConfig.Environment) if err != nil { return nil, err @@ -201,6 +201,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo SubscriptionId: authConfig.SubscriptionID, TenantID: authConfig.TenantID, PartnerId: partnerId, + TerraformVersion: tfVersion, GraphAuthorizer: graphAuth, GraphEndpoint: graphEndpoint, KeyVaultAuthorizer: keyVaultAuth, diff --git a/azurerm/internal/common/client_options.go b/azurerm/internal/common/client_options.go index 7ff752b978c21..abe91cd852fdf 100644 --- a/azurerm/internal/common/client_options.go +++ b/azurerm/internal/common/client_options.go @@ -15,9 +15,10 @@ import ( ) type ClientOptions struct { - SubscriptionId string - TenantID string - PartnerId string + SubscriptionId string + TenantID string + PartnerId string + TerraformVersion string GraphAuthorizer autorest.Authorizer GraphEndpoint string @@ -33,7 +34,7 @@ type ClientOptions struct { } func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.Authorizer) { - setUserAgent(c, o.PartnerId) + setUserAgent(c, o.TerraformVersion, o.PartnerId) c.Authorizer = authorizer c.Sender = sender.BuildSender("AzureRM") @@ -44,8 +45,8 @@ func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.A } } -func setUserAgent(client *autorest.Client, partnerID string) { - tfUserAgent := httpclient.UserAgentString() +func setUserAgent(client *autorest.Client, tfVersion, partnerID string) { + tfUserAgent := httpclient.TerraformUserAgent(tfVersion) providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, version.ProviderVersion) client.UserAgent = strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent)) diff --git a/azurerm/provider.go b/azurerm/provider.go index 23dc586df32eb..7acabca72ca71 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -638,7 +638,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { skipProviderRegistration := d.Get("skip_provider_registration").(bool) disableCorrelationRequestID := d.Get("disable_correlation_request_id").(bool) - client, err := getArmClient(config, skipProviderRegistration, partnerId, disableCorrelationRequestID) + client, err := getArmClient(config, skipProviderRegistration, p.TerraformVersion, partnerId, disableCorrelationRequestID) if err != nil { return nil, err } diff --git a/azurerm/required_resource_providers_test.go b/azurerm/required_resource_providers_test.go index 0850a25e8e523..eb7735f2c69fa 100644 --- a/azurerm/required_resource_providers_test.go +++ b/azurerm/required_resource_providers_test.go @@ -14,7 +14,7 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } // this test intentionally checks all the RP's are registered - so this is intentional - armClient, err := getArmClient(config, true, "", true) + armClient, err := getArmClient(config, true, "0.0.0", "", true) if err != nil { t.Fatalf("Error building ARM Client: %+v", err) } diff --git a/azurerm/resource_arm_container_registry_migrate_test.go b/azurerm/resource_arm_container_registry_migrate_test.go index 4231825052bcc..a354eac1cfcaf 100644 --- a/azurerm/resource_arm_container_registry_migrate_test.go +++ b/azurerm/resource_arm_container_registry_migrate_test.go @@ -21,7 +21,7 @@ func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) { return } - client, err := getArmClient(config, false, "", true) + client, err := getArmClient(config, false, "0.0.0", "", true) if err != nil { t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) return diff --git a/azurerm/resource_arm_data_lake_store_file_migration_test.go b/azurerm/resource_arm_data_lake_store_file_migration_test.go index 1373037f0f683..6ed3a7e20d79c 100644 --- a/azurerm/resource_arm_data_lake_store_file_migration_test.go +++ b/azurerm/resource_arm_data_lake_store_file_migration_test.go @@ -16,7 +16,7 @@ func TestAccAzureRMDataLakeStoreFileMigrateState(t *testing.T) { return } - client, err := getArmClient(config, false, "", true) + client, err := getArmClient(config, false, "0.0.0", "", true) if err != nil { t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) return diff --git a/azurerm/resource_arm_storage_blob_migration_test.go b/azurerm/resource_arm_storage_blob_migration_test.go index 8c941c7999844..273adb66339e2 100644 --- a/azurerm/resource_arm_storage_blob_migration_test.go +++ b/azurerm/resource_arm_storage_blob_migration_test.go @@ -16,7 +16,7 @@ func TestAccAzureRMStorageBlobMigrateState(t *testing.T) { return } - client, err := getArmClient(config, false, "", true) + client, err := getArmClient(config, false, "0.0.0", "", true) if err != nil { t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) return diff --git a/azurerm/resource_arm_storage_container_migration_test.go b/azurerm/resource_arm_storage_container_migration_test.go index b772aa6bf9a19..ddf1e2ee9ea96 100644 --- a/azurerm/resource_arm_storage_container_migration_test.go +++ b/azurerm/resource_arm_storage_container_migration_test.go @@ -16,7 +16,7 @@ func TestAccAzureRMStorageContainerMigrateState(t *testing.T) { return } - client, err := getArmClient(config, false, "", true) + client, err := getArmClient(config, false, "0.0.0", "", true) if err != nil { t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) return diff --git a/azurerm/resource_arm_storage_queue_migration_test.go b/azurerm/resource_arm_storage_queue_migration_test.go index d82856e662ea8..33ca2d6da8490 100644 --- a/azurerm/resource_arm_storage_queue_migration_test.go +++ b/azurerm/resource_arm_storage_queue_migration_test.go @@ -16,7 +16,7 @@ func TestAccAzureRMStorageQueueMigrateState(t *testing.T) { return } - client, err := getArmClient(config, false, "", true) + client, err := getArmClient(config, false, "0.0.0", "", true) if err != nil { t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err)) return