Microsoft.Common.TagsByResource UI 元素Microsoft.Common.TagsByResource UI element

一个控件,用于将标记与部署中的资源相关联。A control for associating tags with the resources in a deployment.

UI 示例UI sample



  "name": "element1",
  "type": "Microsoft.Common.TagsByResource",
  "resources": [

示例输出Sample output

  "Microsoft.Storage/storageAccounts": {
    "Dept": "Finance",
    "Environment": "Production"
  "Microsoft.Compute/virtualMachines": {
    "Dept": "Finance"


  • 必须至少指定 resources 数组中的一项。At least one item in the resources array must be specified.

  • resources 中的每个元素都必须是完全限定的资源类型。Each element in resources must be a fully qualified resource type. 这些元素显示在“资源” 下拉列表中,并且可供用户标记。These elements appear in the Resource dropdown, and are taggable by the user.

  • 控件的输出进行了格式设置,以便于在 Azure 资源管理器模板中轻松分配标记值。The output of the control is formatted for easy assignment of tag values in an Azure Resource Manager template. 若要在模板中接收控件的输出,请在模板中包括参数,如以下示例中所示:To receive the control's output in a template, include a parameter in your template as shown in the following example:

    "parameters": {
    "tagsByResource": { "type": "object", "defaultValue": {} }

    对于可以标记的每个资源,请将标记属性分配给该资源类型的参数值:For each resource that can be tagged, assign the tags property to the parameter value for that resource type:

    "name": "saName1",
    "type": "Microsoft.Storage/storageAccounts",
    "tags": "[ if(contains(parameters('tagsByResource'), 'Microsoft.Storage/storageAccounts'), parameters('tagsByResource')['Microsoft.Storage/storageAccounts'], json('{}')) ]",
  • 在访问 tagsByResource 参数时,请使用 if 函数。Use the if function when accessing the tagsByResource parameter. 当没有任何标记分配给给定的资源类型时,可以使用该函数来分配空对象。It enables you to assign an empty object when no tags are assigned to the given resource type.

后续步骤Next steps