使用模板来标记 VMTagging a VM using a template

本文介绍如何使用资源管理器模板在 Azure 中标记 VM。This article describes how to tag a VM in Azure using a Resource Manager template. 标记是用户定义的键/值对,可直接放置在资源或资源组中。Tags are user-defined key/value pairs which can be placed directly on a resource or a resource group. 针对每个资源和资源组,Azure 当前支持最多 50 个标记。Azure currently supports up to 50 tags per resource and resource group. 标记可以在创建时放置在资源中或添加到现有资源中。Tags may be placed on a resource at the time of creation or added to an existing resource.

此模板将标记放置在以下资源中:计算(虚拟机)、存储(存储帐户)和网络(公共 IP 地址、虚拟网络和网络接口)。This template places tags on the following resources: Compute (Virtual Machine), Storage (Storage Account), and Network (Public IP Address, Virtual Network, and Network Interface). 此模板适用于 Windows VM,但经过改造后也可用于 Linux VM。This template is for a Windows VM but can be adapted for Linux VMs.

单击 模板链接 中的 部署至 Azure 按钮。Click the Deploy to Azure button from the template link. 此操作将导航到 Azure 门户,可在其中部署此模板。This will navigate to the Azure portal where you can deploy this template.

使用标记进行简单部署

此模板包括以下标记:DepartmentApplicationCreated ByThis template includes the following tags: Department, Application, and Created By. 如果想要不同的标记名称,则可以直接在模板中添加/编辑这些标记。You can add/edit these tags directly in the template if you would like different tag names.

模板中的 Azure 标记

如你所见,标记将被定义为键值对,用冒号 (:) 分隔。As you can see, the tags are defined as key/value pairs, separated by a colon (:). 必须按以下格式定义标记:The tags must be defined in this format:

"tags": {
    "Key1" : "Value1",
    "Key2" : "Value2"
}

完成编辑后,使用选择的标记保存模板文件。Save the template file after you finish editing it with the tags of your choice.

接下来,在“编辑参数”部分中,可以填写标记的值。 Next, in the Edit Parameters section, you can fill out the values for your tags.

通过 Azure 门户编辑标记

单击 “创建”使用标记值部署此模板。Click Create to deploy this template with your tag values.

后续步骤Next steps