Roman KlimenkoBlogPhotography

Azure customer usage attribution

October 25, 2021

azurecloud

Microsoft's customer usage attribution works very well for Azure Marketplace applications but if you have to deal with the other cases, there are things you should be aware of.

There are at least four ways to deploy the tracking GUID (pid) outside of the Azure Marketplace:

  1. Add a GUID to a Resource Manager template
  2. Use Resource Manager APIs
  3. Use Terraform

The Resource Manager template approach (ARM) will create a deployment under your resource group. You can see this deployment in the Azure Portal or check it with the script.

However, if you use any other approach to deploy the tracking GUID, the deployment will not be created in your resource group, so you will not see if you used the correct GUID. So you have to remember that you did everything right. And the script mentioned above will not be able to verify it.

Furthermore, the last two approaches are the same - they all use the User Agent value.

Python SDK:

client.config.add_user_agent("pid-b6addd8f-5ff4-4fc0-a2b5-0ec7861106c4")

.NET SDK:

.WithUserAgent("pid-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", String.Empty)

Azure CLI:

export AZURE_HTTP_USER_AGENT='pid-eb7927c8-dd66-43e1-b0cf-c346a422063' # sets the User Agent header

Finally, Terraform:

partner_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}

If you check the Terraform source code, you may be surprised that under the hood, Terraforms sets the User Agent header to the pid value:

func setUserAgent(client *autorest.Client, tfVersion, partnerID string, disableTerraformPartnerID bool) { tfUserAgent := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io) Terraform Plugin SDK/%s", tfVersion, meta.SDKVersionString()) providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, version.ProviderVersion) client.UserAgent = strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent)) // append the CloudShell version to the user agent if it exists if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" { client.UserAgent = fmt.Sprintf("%s %s", client.UserAgent, azureAgent) } // only one pid can be interpreted currently // 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" } if partnerID != "" { client.UserAgent = fmt.Sprintf("%s pid-%s", client.UserAgent, partnerID) } }

Moreover, if you don't specify your tracking GUID (aka pid, aka Partner ID) and don't disable the tracking (enabled by default), Terraform will add their GUID to the User Agent header.

Summary

  1. You can't verify if you installed the correct GUID unless you deployed an ARM template.
  2. The SDK and Terraform approaches are the same - they both send a User Agent header to the server.
  3. If you don't set the disable_terraform_partner_id flag to true (it is false by default), and don't set your own partner_id, Terraform will add their GUID to the User Agent header.