Skip to content

Commit

Permalink
Partner ID: allowing users to opt-out of the default Terraform Partne…
Browse files Browse the repository at this point in the history
…r ID
  • Loading branch information
tombuildsstuff committed Oct 29, 2019
1 parent 1ccffce commit 9b32202
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
3 changes: 2 additions & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,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, tfVersion, partnerId string, disableCorrelationRequestID bool) (*ArmClient, error) {
func getArmClient(authConfig *authentication.Config, skipProviderRegistration bool, tfVersion, partnerId string, disableCorrelationRequestID, disableTerraformPartnerID bool) (*ArmClient, error) {
env, err := authentication.DetermineEnvironment(authConfig.Environment)
if err != nil {
return nil, err
Expand Down Expand Up @@ -221,6 +221,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo
PollingDuration: 180 * time.Minute,
SkipProviderReg: skipProviderRegistration,
DisableCorrelationRequestID: disableCorrelationRequestID,
DisableTerraformPartnerID: disableTerraformPartnerID,
Environment: *env,
}

Expand Down
15 changes: 10 additions & 5 deletions azurerm/internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ type ClientOptions struct {

SkipProviderReg bool
DisableCorrelationRequestID bool
DisableTerraformPartnerID bool
Environment azure.Environment

// TODO: remove me in 2.0
PollingDuration time.Duration
}

func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.Authorizer) {
setUserAgent(c, o.TerraformVersion, o.PartnerId)
setUserAgent(c, o.TerraformVersion, o.PartnerId, o.DisableTerraformPartnerID)

c.Authorizer = authorizer
c.Sender = sender.BuildSender("AzureRM")
Expand All @@ -52,7 +53,7 @@ func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.A
}
}

func setUserAgent(client *autorest.Client, tfVersion, partnerID string) {
func setUserAgent(client *autorest.Client, tfVersion, partnerID string, disableTerraformPartnerID bool) {
tfUserAgent := httpclient.TerraformUserAgent(tfVersion)

providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, version.ProviderVersion)
Expand All @@ -64,12 +65,16 @@ func setUserAgent(client *autorest.Client, tfVersion, partnerID string) {
}

// only one pid can be interpreted currently
// hence, send partner ID if present, otherrwise send Terraform GUID
if partnerID == "" {
// hence, send partner ID if present, otherwise send Terraform GUID
// unless users have opted out
if partnerID == "" && !disableTerraformPartnerID {
// Microsoft’s Terraform Partner ID is this specific GUID
partnerID = "222c6c49-1b0a-5959-a213-6608f9eb8820"
}
client.UserAgent = fmt.Sprintf("%s pid-%s", client.UserAgent, partnerID)

if partnerID != "" {
client.UserAgent = fmt.Sprintf("%s pid-%s", client.UserAgent, partnerID)
}

log.Printf("[DEBUG] AzureRM Client User Agent: %s\n", client.UserAgent)
}
18 changes: 14 additions & 4 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,20 @@ func Provider() terraform.ResourceProvider {
},

"disable_correlation_request_id": {
Type: schema.TypeBool,
Optional: true,
Type: schema.TypeBool,
Optional: true,
// TODO: add an ARM_ prefix in 2.0w
DefaultFunc: schema.EnvDefaultFunc("DISABLE_CORRELATION_REQUEST_ID", false),
Description: "This will disable the x-ms-correlation-request-id header.",
},

"disable_terraform_partner_id": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_DISABLE_TERRAFORM_PARTNER_ID", false),
Description: "This will disable the Terraform Partner ID which is used if a custom `partner_id` isn't specified.",
},

// Advanced feature flags
"skip_credentials_validation": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -651,7 +659,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
}

if len(auxTenants) > 3 {
return nil, fmt.Errorf("The provider onlt supports 3 auxiliary tenant IDs")
return nil, fmt.Errorf("The provider only supports 3 auxiliary tenant IDs")
}

builder := &authentication.Builder{
Expand Down Expand Up @@ -684,6 +692,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
partnerId := d.Get("partner_id").(string)
skipProviderRegistration := d.Get("skip_provider_registration").(bool)
disableCorrelationRequestID := d.Get("disable_correlation_request_id").(bool)
disableTerraformPartnerID := d.Get("disable_terraform_partner_id").(bool)

terraformVersion := p.TerraformVersion
if terraformVersion == "" {
Expand All @@ -692,7 +701,8 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
terraformVersion = "0.11+compatible"
}

client, err := getArmClient(config, skipProviderRegistration, terraformVersion, partnerId, disableCorrelationRequestID)
// TODO: we should pass in an Object here
client, err := getArmClient(config, skipProviderRegistration, terraformVersion, partnerId, disableCorrelationRequestID, disableTerraformPartnerID)
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, "0.0.0", "", true)
armClient, err := getArmClient(config, true, "0.0.0", "", true, false)
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, "0.0.0", "", true)
client, err := getArmClient(config, false, "0.0.0", "", true, false)
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, "0.0.0", "", true)
client, err := getArmClient(config, false, "0.0.0", "", true, false)
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, "0.0.0", "", true)
client, err := getArmClient(config, false, "0.0.0", "", true, false)
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, "0.0.0", "", true)
client, err := getArmClient(config, false, "0.0.0", "", true, false)
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, "0.0.0", "", true)
client, err := getArmClient(config, false, "0.0.0", "", true, false)
if err != nil {
t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err))
return
Expand Down
2 changes: 2 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ More information on [how to configure a Service Principal using Managed Service

For some advanced scenarios, such as where more granular permissions are necessary - the following properties can be set:

* `disable_terraform_partner_id` - (Optional) Disable sending the Terraform Partner ID if a custom `partner_id` isn't specified, which allows Microsoft to better understand the usage of Terraform. The Partner ID does not give HashiCorp any direct access to usage information. This can also be sourced from the `ARM_DISABLE_TERRAFORM_PARTNER_ID` environment variable. Defaults to `false`.

* `partner_id` - (Optional) A GUID/UUID that is [registered](https://docs.microsoft.com/azure/marketplace/azure-partner-customer-usage-attribution#register-guids-and-offers) with Microsoft to facilitate partner resource usage attribution. This can also be sourced from the `ARM_PARTNER_ID` Environment Variable.

* `skip_credentials_validation` - (Optional) Should the AzureRM Provider skip verifying the credentials being used are valid? This can also be sourced from the `ARM_SKIP_CREDENTIALS_VALIDATION` Environment Variable. Defaults to `false`.
Expand Down

0 comments on commit 9b32202

Please sign in to comment.