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

Support for specifying the Partner ID #2643

Merged
merged 5 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion azurerm/azurerm_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func buildConfigForSweepers() (*ArmClient, error) {
return nil, fmt.Errorf("Error building ARM Client: %+v", err)
}

return getArmClient(config, false)
return getArmClient(config, false, "")
}

func shouldSweepAcceptanceTestResource(name string, resourceLocation string, region string) bool {
Expand Down
14 changes: 10 additions & 4 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type ArmClient struct {
clientId string
tenantId string
subscriptionId string
partnerId string
usingServicePrincipal bool
environment az.Environment
skipProviderRegistration bool
Expand Down Expand Up @@ -349,15 +350,15 @@ func clientRequestID() string {
}

func (c *ArmClient) configureClient(client *autorest.Client, auth autorest.Authorizer) {
setUserAgent(client)
setUserAgent(client, c.partnerId)
client.Authorizer = auth
//client.RequestInspector = azure.WithClientID(clientRequestID())
client.Sender = azure.BuildSender()
client.SkipResourceProviderRegistration = c.skipProviderRegistration
client.PollingDuration = 60 * time.Minute
}

func setUserAgent(client *autorest.Client) {
func setUserAgent(client *autorest.Client, partnerID string) {
// TODO: This is the SDK version not the CLI version, once we are on 0.12, should revisit
tfUserAgent := httpclient.UserAgentString()

Expand All @@ -370,12 +371,16 @@ func setUserAgent(client *autorest.Client) {
client.UserAgent = fmt.Sprintf("%s %s", client.UserAgent, azureAgent)
}

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

log.Printf("[DEBUG] AzureRM Client User Agent: %s\n", client.UserAgent)
}

// getArmClient is a helper method which returns a fully instantiated
// *ArmClient based on the Config's current settings.
func getArmClient(c *authentication.Config, skipProviderRegistration bool) (*ArmClient, error) {
func getArmClient(c *authentication.Config, skipProviderRegistration bool, partnerId string) (*ArmClient, error) {
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
env, err := authentication.DetermineEnvironment(c.Environment)
if err != nil {
return nil, err
Expand All @@ -386,6 +391,7 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool) (*Arm
clientId: c.ClientID,
tenantId: c.TenantID,
subscriptionId: c.SubscriptionID,
partnerId: partnerId,
environment: *env,
usingServicePrincipal: c.AuthenticatedAsAServicePrincipal,
skipProviderRegistration: skipProviderRegistration,
Expand Down Expand Up @@ -726,7 +732,7 @@ func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth auto
c.sqlDatabasesClient = sqlDBClient

sqlDTDPClient := sql.NewDatabaseThreatDetectionPoliciesClientWithBaseURI(endpoint, subscriptionId)
setUserAgent(&sqlDTDPClient.Client)
setUserAgent(&sqlDTDPClient.Client, "")
sqlDTDPClient.Authorizer = auth
sqlDTDPClient.Sender = sender
sqlDTDPClient.SkipResourceProviderRegistration = c.skipProviderRegistration
Expand Down
13 changes: 12 additions & 1 deletion azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
)

// Provider returns a terraform.ResourceProvider.
Expand Down Expand Up @@ -74,6 +75,14 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("ARM_MSI_ENDPOINT", ""),
},

// Managed Tracking GUID for User-agent
"partner_id": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ARM_PARTNER_ID", ""),
ValidateFunc: validate.UUID,
},

// Advanced feature flags
"skip_credentials_validation": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -366,8 +375,10 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
return nil, fmt.Errorf("Error building AzureRM Client: %s", err)
}

partnerId := d.Get("partner_id").(string)
skipProviderRegistration := d.Get("skip_provider_registration").(bool)
client, err := getArmClient(config, skipProviderRegistration)
client, err := getArmClient(config, skipProviderRegistration, partnerId)

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)
armClient, err := getArmClient(config, 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 @@ -19,7 +19,7 @@ func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) {
return
}

client, err := getArmClient(config, false)
client, err := getArmClient(config, 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)
client, err := getArmClient(config, 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)
client, err := getArmClient(config, 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)
client, err := getArmClient(config, 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)
client, err := getArmClient(config, 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_table_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccAzureRMStorageTableMigrateState(t *testing.T) {
return
}

client, err := getArmClient(config, false)
client, err := getArmClient(config, false, "")
if err != nil {
t.Fatal(fmt.Errorf("Error building ARM Client: %+v", err))
return
Expand Down
6 changes: 6 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ For some advanced scenarios, such as where more granular permissions are necessa
* `skip_provider_registration` - (Optional) Should the AzureRM Provider skip registering any required Resource Providers? This can also be sourced from the `ARM_SKIP_PROVIDER_REGISTRATION` Environment Variable. Defaults to `false`.

It's also possible to use multiple Provider blocks within a single Terraform configuration, for example to work with resources across multiple Subscriptions - more information can be found [in the documentation for Providers](https://www.terraform.io/docs/configuration/providers.html#multiple-provider-instances).

---

Additional advanced configuration includes:

* `partner_id` - (Optional) A GUID/UUID provided by Microsoft that is added to the user agent to facilitate partner resource usage data collection. This can also be sourced from the `ARM_PARTNER_ID` Environment Variable. Defaults to an empty string.
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved