Share via


將 Microsoft.Resources 資源移至新區域

您可能會需要將現有資源移至新的區域。 本文說明如何移動位於 Microsoft.Resources 命名空間的兩個資源類型:templateSpecs 和 deploymentScripts。

將範本規格移至新區域

若您在某區域中有個範本規格且要移至新區域,您可匯出該範本規格並將其重新部署。

  1. 使用命令匯出現有的範本規格。針對參數值,請提供與要匯出的範本規格相符的值。

    如果是 Azure PowerShell,請使用:

    Export-AzTemplateSpec `
      -ResourceGroupName demoRG `
      -Name demoTemplateSpec `
      -Version 1.0 `
      -OutputFolder c:\export
    

    對於 Azure CLI,請使用:

    az template-specs export \
      --resource-group demoRG \
      --name demoTemplateSpec \
      --version 1.0 \
      --output-folder c:\export
    
  2. 使用匯出的範本規格建立新的範本規格。下列範例顯示新區域的 westus,但您可以提供您要的區域。

    如果是 Azure PowerShell,請使用:

    New-AzTemplateSpec `
      -Name movedTemplateSpec `
      -Version 1.0 `
      -ResourceGroupName newRG `
      -Location westus `
      -TemplateJsonFile c:\export\1.0.json
    

    對於 Azure CLI,請使用:

    az template-specs create \
      --name movedTemplateSpec \
      --version "1.0" \
      --resource-group newRG \
      --location "westus" \
      --template-file "c:\export\demoTemplateSpec.json"
    

將部署指令碼移至新區域

  1. 選取資源群組,其包含要移至新區域的部署指令碼。

  2. 匯出範本。 匯出時,請選取部署指令碼和任何其他必要的資源。

  3. 在匯出的範本中,刪除下列屬性:

    • tenantId
    • principalId
    • clientId
  4. 匯出的範本具有部署指令碼區域的硬式編碼值。

    "location": "westus2",
    

    變更範本,允許使用設定位置的參數。 如需詳細資訊,請參閱在 ARM 範本中設定資源位置

    "location": "[parameters('location')]",
    
  5. 部署匯出的範本,並指定部署指令碼的新區域。

下一步