|
| 1 | +--- |
| 2 | +title: Azure TagsByResource UI element |
| 3 | +description: Describes the Microsoft.Common.TagsByResource UI element for Azure portal. Use to apply tags to a resource during deployment. |
| 4 | +author: tfitzmac |
| 5 | + |
| 6 | +ms.service: managed-applications |
| 7 | +ms.topic: reference |
| 8 | +ms.date: 11/11/2019 |
| 9 | +ms.author: tomfitz |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +# Microsoft.Common.TagsByResource UI element |
| 14 | + |
| 15 | +A control for associating [tags](../azure-resource-manager/resource-group-using-tags.md) with the resources in a deployment. |
| 16 | + |
| 17 | +## UI sample |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Schema |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "name": "element1", |
| 26 | + "type": "Microsoft.Common.TagsByResource", |
| 27 | + "resources": [ |
| 28 | + "Microsoft.Storage/storageAccounts", |
| 29 | + "Microsoft.Compute/virtualMachines" |
| 30 | + ] |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +## Sample output |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "Microsoft.Storage/storageAccounts": { |
| 39 | + "Dept": "Finance", |
| 40 | + "Environment": "Production" |
| 41 | + }, |
| 42 | + "Microsoft.Compute/virtualMachines": { |
| 43 | + "Dept": "Finance" |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +## Remarks |
| 49 | + |
| 50 | +- At least one item in the `resources` array must be specified. |
| 51 | +- Each element in `resources` must be a fully qualified resource type. These elements appear in the **Resource** dropdown, and are taggable by the user. |
| 52 | +- 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: |
| 53 | + |
| 54 | + ```json |
| 55 | + "parameters": { |
| 56 | + "tagsByResource": { "type": "object", "defaultValue": {} } |
| 57 | + } |
| 58 | + ``` |
| 59 | + |
| 60 | + For each resource that can be tagged, assign the tags property to the parameter value for that resource type: |
| 61 | + |
| 62 | + ```json |
| 63 | + { |
| 64 | + "name": "saName1", |
| 65 | + "type": "Microsoft.Storage/storageAccounts", |
| 66 | + "tags": "[ if(contains(parameters('tagsByResource'), 'Microsoft.Storage/storageAccounts'), parameters('tagsByResource')['Microsoft.Storage/storageAccounts'], json('{}')) ]", |
| 67 | + ... |
| 68 | + ``` |
| 69 | + |
| 70 | +- Use the [if](../azure-resource-manager/resource-group-template-functions-logical.md#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. |
| 71 | + |
| 72 | +## Next steps |
| 73 | + |
| 74 | +- For an introduction to creating UI definitions, see [Getting started with CreateUiDefinition](create-uidefinition-overview.md). |
| 75 | +- For a description of common properties in UI elements, see [CreateUiDefinition elements](create-uidefinition-elements.md). |
0 commit comments