Skip to content

Commit

Permalink
Support setting a custom partner ID, or disbling the partner ID in th…
Browse files Browse the repository at this point in the history
…e user-agent string
  • Loading branch information
manicminer committed Nov 10, 2020
1 parent 58055a7 commit 81156f6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
14 changes: 9 additions & 5 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion internal/services/configure_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).

0 comments on commit 81156f6

Please sign in to comment.