通过 User-Agent header 标记 Azure 合作伙伴资源

Azure partner resource tagging via User-Agent header

我正在尝试实施 partner tagging of Azure resources by adding a partner product GUID to the User-Agent header when creating resources via the Resource Manager API, but it doesn't have any visible effect. I checked the ARM template of a "tagged" resource, but the GUID is not there. Verification method 文章中描述的也给出了负面结果。

它对任何人都有效吗?

以下是基于上述指南的 Powershell 代码,可重现该问题:

Install-Module -Name Az -AllowClobber -Scope CurrentUser # installs Azure Powerhsell module
$partnerID = "pid-3fd1a53d-3ef0-4111-8a66-211ed6470935" # Product GUID
$VMLocalAdminUser = "partneridtest" # test VM username
$VMLocalAdminSecurePassword = ConvertTo-SecureString "Pa$$word123" -AsPlainText -Force # test VM password
$resourceGroupName=[guid]::NewGuid().ToString() # randomly generated resource group name
Import-Module -Name Az # import Azure Powerhsell module
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent($partnerID) # add user-agent for partner tracking

Connect-AzAccount # login to Azure

New-AzResourceGroup -Name $resourceGroupName -Location eastus # create a resource group
Write-Host Resource group name $resourceGroupName

$vmParams = @{
  ResourceGroupName = $resourceGroupName
  Name = 'PartnerIdTest1'
  Location = 'eastus'
  ImageName = 'Win2016Datacenter'
  PublicIpAddressName = 'partnerIdTestPublicIp'
  Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword)
  OpenPorts = 3389
}
$newVM1 = New-AzVM @vmParams # create a test VM (should be tagged with the partner product guid)

Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name $partnerID # fails with Get-AzResourceGroupDeployment : Deployment 'pid-3fd1a53d-3ef0-4111-8a66-211ed6470935' could not be found.

注意:上面的 GUID 是随机的 - 不是真实的。它应该替换为注册合作伙伴 GUID。

这不是一个工作示例,不适合评论。

Get-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -Name $partnerID 尝试在资源组中搜索名称为 $partnerID 的部署,但 New-AzVM 可能正在使用 virtualmachine-<some_random_id> 这样的名称。要像您尝试的那样使用命令,部署必须具有相同的名称。此名称可以在 ARM 模板中或使用 New-AzResourceGroupDeployment 命令给出。

我不太了解合作伙伴标记,但该命令通常无法像您尝试使用它那样工作。

此外,如果您的 $productID 值对于多个部署保持相同,但对部署使用相同的名称将覆盖以前的部署(基本上您只丢失了部署历史记录)。我建议检查门户中的资源组并获取部署名称,或者使用不带 Name 参数的 Get-AzResourceGroupDeployment 来获取所有部署并根据部署时间查找相关部署。

我还要指出,您似乎正在使用资源管理器 API 进程,但 documentation 声明以下验证方法 -

You can use the script to verify that the GUID is successfully added to your Resource Manager template. The script doesn't apply to Resource Manager API or Terraform deployments.

您的代码可能有效,但我没有看到使用 User-Agent 方法时的明确验证方法。 (可能会根据文档检查合作伙伴中心分析仪表板中的报告?)。 ARM模板好像有验证方法,你可以试试

在部署期间标记资源以进行归因时,资源本身看不到任何指示关联的内容,这是内部实现。

如果您的目标是验证您编写的代码是否正常工作(这样资源将被正确归属),目前无法在外部为 UserAgent 方法执行此操作 - 我们只能在内部执行.您可以使用链接到的文档中的脚本验证模板部署,但这仅适用于模板部署,API 调用(TF、SDK 等)。

您不会在合作伙伴门户中看到任何内容,除非 1) 已注册 GUID 并且 2) 资源有计费使用。

综上所述 - 我快速浏览了日志,确实看到在 userAgent 中使用 3fd1a53d-3ef0-4111-8a66-211ed6470935 配置了一些资源。

有帮助吗?