diff --git a/internal/clients/builder.go b/internal/clients/builder.go index f4d882e1e0..2b3a65b9a4 100644 --- a/internal/clients/builder.go +++ b/internal/clients/builder.go @@ -13,8 +13,10 @@ import ( ) type ClientBuilder struct { - AuthConfig *authentication.Config - TerraformVersion string + AuthConfig *authentication.Config + DisableTerraformPartnerID bool + PartnerID string + TerraformVersion string } // Build is a helper method which returns a fully instantiated *AadClient based on the auth Config's current settings. @@ -54,9 +56,11 @@ func (b *ClientBuilder) Build(ctx context.Context) (*AadClient, error) { } o := &services.ClientOptions{ - TenantID: b.AuthConfig.TenantID, - TerraformVersion: b.TerraformVersion, - Environment: *env, + DisableTerraformPartnerID: b.DisableTerraformPartnerID, + PartnerID: b.PartnerID, + TenantID: b.AuthConfig.TenantID, + TerraformVersion: b.TerraformVersion, + Environment: *env, } // Graph Endpoints diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 1b25fec68b..73fb4ee9b0 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/go-azure-helpers/authentication" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azuread/internal/clients" @@ -136,6 +137,22 @@ func AzureADProvider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("ARM_MSI_ENDPOINT", ""), Description: "The path to a custom endpoint for Managed Service Identity - in most circumstances this should be detected automatically. ", }, + + // Managed Tracking GUID for User-agent + "partner_id": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.Any(validation.IsUUID, validation.StringIsEmpty), + DefaultFunc: schema.EnvDefaultFunc("ARM_PARTNER_ID", ""), + Description: "A GUID/UUID that is registered with Microsoft to facilitate partner resource usage attribution.", + }, + + "disable_terraform_partner_id": { + Type: schema.TypeBool, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("ARM_DISABLE_TERRAFORM_PARTNER_ID", false), + Description: "Disable the Terraform Partner ID which is used if a custom `partner_id` isn't specified.", + }, }, ResourcesMap: resources, @@ -181,8 +198,10 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc { } clientBuilder := clients.ClientBuilder{ - AuthConfig: config, - TerraformVersion: terraformVersion, + AuthConfig: config, + PartnerID: d.Get("partner_id").(string), + DisableTerraformPartnerID: d.Get("disable_terraform_partner_id").(bool), + TerraformVersion: terraformVersion, } client, err := clientBuilder.Build(p.StopContext()) diff --git a/internal/services/configure_client.go b/internal/services/configure_client.go index 82e0832839..8be220a7bf 100644 --- a/internal/services/configure_client.go +++ b/internal/services/configure_client.go @@ -14,6 +14,8 @@ import ( "github.com/terraform-providers/terraform-provider-azuread/version" ) +const TerraformPartnerID = "222c6c49-1b0a-5959-a213-6608f9eb8820" + type ClientOptions struct { TenantID string Environment azure.Environment @@ -48,7 +50,7 @@ func setUserAgent(client *autorest.Client, tfVersion, partnerID string, disableT // unless users have opted out if partnerID == "" && !disableTerraformPartnerID { // Microsoft’s Terraform Partner ID is this specific GUID - partnerID = "222c6c49-1b0a-5959-a213-6608f9eb8820" + partnerID = TerraformPartnerID } if partnerID != "" { diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index ed48986dc2..dd6ecc5a45 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -119,8 +119,12 @@ More information on [how to configure a Service Principal using Managed Service For more advanced scenarios, the following additional arguments are supported: +* `disable_terraform_partner_id` - (Optional) Disable sending the Terraform Partner ID if a custom `partner_id` isn't specified. The default Partner ID allows Microsoft to better understand the usage of Terraform and 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`. + * `metadata_host` - (Optional) The Hostname of the Azure Metadata Service (for example `management.azure.com`), used to obtain the Cloud Environment when using a Custom Azure Environment. This can also be sourced from the `ARM_METADATA_HOST` Environment Variable. ~> **Note:** `environment` must be set to the requested environment name in the list of available environments held in the `metadata_host`. +* `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. + It's also possible to use multiple Provider blocks within a single Terraform configuration, for example to work with resources across multiple Azure Active Directory Environments - more information can be found [in the documentation for Providers](https://www.terraform.io/docs/configuration/providers.html#multiple-provider-instances).