單一和多重資源匯出至 Azure 入口網站中的範本Single and multi-resource export to a template in Azure portal

若要協助建立 Azure Resource Manager 範本,您可以從現有的資源匯出範本。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 可讓您挑選一或多個要匯出至範本的資源。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.

從資源群組匯出範本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.

匯出的範本是從每個資源類型的已發行架構產生的。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.

從資源匯出範本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