在 Azure 门户中将单资源和多资源导出到模板Single and multi-resource export to a template in Azure portal

为了帮助创建 Azure 资源管理器模板,可以从现有的资源导出模板。To assist with creating Azure Resource Manager templates, you can export a template from existing resources. 导出的模板可帮助你了解用于部署资源的 JSON 语法和属性。The exported template helps you understand the JSON syntax and properties that deploy your resources. 若要自动完成将来的部署,可从导出的模板着手,根据具体的方案修改此模板。To automate future deployments, start with the exported template and modify it for your scenario.

在资源管理器中,可以选择一个或多个要导出到模板的资源。Resource Manager enables you to pick one or more resources for exporting to a template. 你可以完全专注于模板中所需的资源。You can focus on exactly the resources you need in the template.

本文介绍如何通过门户导出模板。This article shows how to export templates through the portal. 也可以使用 Azure CLIAzure PowerShellREST APIYou can also use Azure CLI, Azure PowerShell, or REST API.

选择适当的导出选项Choose the right export option

可以通过两种方式来导出模板:There are two ways to export a template:

  • 从资源组或资源导出Export from resource group or resource. 此选项基于现有的资源生成新模板。This option generates a new template from existing resources. 导出的模板是资源组当前状态的“快照”。The exported template is a "snapshot" of the current state of the resource group. 可以导出整个资源组,或该资源组中的特定资源。You can export an entire resource group or specific resources within that resource group.

  • 在部署之前导出或从历史记录导出Export before deployment or from history. 此选项检索用于部署的确切模板副本。This option retrieves an exact copy of a template used for deployment.

根据所选的选项,导出的模板具有不同的质量。Depending on the option you choose, the exported templates have different qualities.

从资源组或资源From resource group or resource 在部署之前或从历史记录Before deployment or from history
模板是资源当前状态的快照。Template is snapshot of the resources' current state. 其中包含你在部署之后所做的任何手动更改。It includes any manual changes you made after deployment. 模板仅显示资源在部署时的状态。Template only shows state of resources at the time of deployment. 不包含部署之后所做的任何手动更改。Any manual changes you made after deployment aren't included.
可以从资源组中选择要导出的资源。You can select which resources from a resource group to export. 包含特定部署的所有资源。All resources for a specific deployment are included. 不能选取其中的一部分资源,或者包含在不同时间添加的资源。You can't pick a subset of those resources or add resources that were added at a different time.
模板包含资源的所有属性,包括部署过程中通常不会设置的某些属性。Template includes all properties for the resources, including some properties you wouldn't normally set during deployment. 在重复使用模板之前,你可能需要删除或清理这些属性。You might want to remove or clean up these properties before reusing the template. 模板仅包含部署所需的属性。Template includes only the properties needed for the deployment. 模板随时可供使用。The template is ready-to-use.
模板可能不包含重复使用它所需的所有参数。Template probably doesn't include all of the parameters you need for reuse. 大多数属性值在模板中已硬编码。Most property values are hard-coded in the template. 若要在其他环境中重新部署模板,需要添加参数,以提高配置资源的能力。To redeploy the template in other environments, you need to add parameters that increase the ability to configure the resources. 可以取消选择“包括参数”,这样就可以创作自己的参数 。You can unselect Include parameters so that you can author your own parameters. 模板包含一些参数以方便在不同的环境中重新部署。Template includes parameters that make it easy to redeploy in different environments.

在以下情况下,请从资源组或资源导出模板:Export the template from a resource group or resource, when:

  • 需要捕获在原始部署之后对资源所做的更改。You need to capture changes to the resources that were made after the original deployment.
  • 想要选择要导出的资源。You want to select which resources are exported.

在以下情况下,请在部署之前或者从历史记录导出模板:Export the template before deployment or from the history, when:

  • 想要一个易于重复使用的模板。You want an easy-to-reuse template.
  • 不需要包含原始部署之后所做的更改。You don't need to include changes you made after the original deployment.


从资源组或资源进行导出时,将通过每种资源类型的已发布架构生成导出的模板。When exporting from a resource group or resource, the exported template is generated from the published schemas for each resource type. 有时,架构没有资源类型的最新版本。Occasionally, the schema doesn't have the latest version for a resource type. 检查导出的模板,确保其包含所需的属性。Check your exported template to make sure it includes the properties you need. 如有必要,请编辑导出的模板,以使用所需的 API 版本。If necessary, edit the exported template to use the API version you need.

导出模板功能不支持导出 Azure 数据工厂资源。The export template feature doesn't support exporting Azure Data Factory resources. 若要了解如何导出数据工厂资源,请参阅在 Azure 数据工厂中复制或克隆数据工厂To learn about how you can export Data Factory resources, see Copy or clone a data factory in Azure Data Factory.

若要导出通过经典部署模型创建的资源,必须将其迁移到资源管理器部署模型To export resources created through classic deployment model, you must migrate them to the Resource Manager deployment model.

从资源组导出模板Export template from a resource group

若要从资源组中导出一个或多个资源:To export one or more resources from a resource group:

  1. 选择包含所要导出的资源的资源组。Select the resource group that contains the resources you want to export.

  2. 通过选中相应的复选框选择一个或多个资源。Select one or more resources by selecting the checkboxes. 若要全选,请选中名称左侧的复选框。To select all, select the checkbox on the left of Name. “导出模板” 菜单项只有在你选择了至少一个资源之后才会启用。The Export template menu item only becomes enabled after you've selected at least one resource.


    在屏幕截图中,只选择了存储帐户。On the screenshot, only the storage account is selected.

  3. 选择“导出模板” 。Select Export template.

  4. 此时将显示导出的模板,并可供下载和部署。The exported template is displayed, and is available to download and deploy.


    “包括参数”默认情况下已选中。Include parameters is selected by default. 如果选中,生成模板时将包括所有模板参数。When selected, all template parameters will be included when the template is generated. 如果希望创作自己的参数,请将此复选框切换为不包括参数。If you'd like to author your own parameters, toggle this checkbox to not include them.

从资源导出模板Export template from a resource

导出一个资源:To export one resource:

  1. 选择包含所要导出的资源的资源组。Select the resource group containing the resource you want to export.

  2. 选择要导出的资源以打开资源。Select the resource that you want to export to open the resource.

  3. 在左窗格中选择该资源对应的“导出模板”。 For that resource, select Export template in the left pane.


  4. 此时将显示导出的模板,并且该模板可供下载和部署。The exported template is displayed, and is available to download and deploy. 模板只包含单个资源。The template only contains the single resource. “包括参数”默认情况下已选中。Include parameters is selected by default. 如果选中,生成模板时将包括所有模板参数。When selected, all template parameters will be included when the template is generated. 如果希望创作自己的参数,请将此复选框切换为不包括参数。If you'd like to author your own parameters, toggle this checkbox to not include them.

在部署之前导出模板Export template before deployment

  1. 选择要部署的 Azure 服务。Select the Azure service you want to deploy.

  2. 填写新服务的值。Fill in the values for the new service.

  3. 在通过验证之后、开始部署之前,请选择“下载自动化模板”。 After passing validation, but before starting the deployment, select Download a template for automation.


  4. 此时将显示该模板,并且该模板可供下载和部署。The template is displayed and is available for download and deploy.

在部署之后导出模板Export template after deployment

可以导出用于部署现有资源的模板。You can export the template that was used to deploy existing resources. 获取的模板正是用于部署的模板。The template you get is exactly the one that was used for deployment.

  1. 选择要导出的资源组。Select the resource group you want to export.

  2. 选择“部署”下面的链接。 Select the link under Deployments.


  3. 从部署历史记录中选择一个部署。Select one of the deployments from the deployment history.


  4. 选择“模板”。 Select Template. 随后,用于此部署的模板将会显示,并可供下载。The template used for this deployment is displayed, and is available for download.


后续步骤Next steps