Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: Use real Terraform version #4464

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions azurerm/internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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))
Expand Down
9 changes: 8 additions & 1 deletion azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,14 @@ 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)
terraformVersion := p.TerraformVersion
if terraformVersion == "" {
// Terraform 0.12 introduced this field to the protocol
// We can therefore assume that if it's missing it's 0.10 or 0.11
terraformVersion = "0.11+compatible"
}

client, err := getArmClient(config, skipProviderRegistration, terraformVersion, partnerId, disableCorrelationRequestID)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/required_resource_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_container_registry_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_storage_blob_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_storage_container_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_storage_queue_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down