Azure 资源管理器部署模式Azure Resource Manager deployment modes

部署资源时,可以指定部署为增量更新还是完整更新。When deploying your resources, you specify that the deployment is either an incremental update or a complete update. 这两种模式的主要区别是资源管理器如何处理资源组中不在模板中的现有资源。The primary difference between these two modes is how Resource Manager handles existing resources in the resource group that aren't in the template. 默认模式为增量模式。The default mode is incremental.

对于这两种模式,资源管理器都会尝试创建模板中指定的所有资源。For both modes, Resource Manager tries to create all resources specified in the template. 如果资源已存在于资源组中且其设置未更改,则不会对该资源执行任何操作。If the resource already exists in the resource group and its settings are unchanged, no operation is taken for that resource. 如果更改资源的属性值,则使用这些新值更新资源。If you change the property values for a resource, the resource is updated with those new values. 如果尝试更新现有资源的位置或类型,则部署会失败并出现错误。If you try to update the location or type of an existing resource, the deployment fails with an error. 请改用所需的位置或类型部署新资源。Instead, deploy a new resource with the location or type that you need.

完整模式Complete mode

在完整模式下,资源管理器删除资源组中已存在但尚未在模板中指定的资源 。In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template. 由于条件的计算结果为 false,因此不会删除模板中指定但未部署的资源。Resources that are specified in the template, but not deployed because a condition evaluates to false, aren't deleted.

将完整模式与复制循环一起使用时要小心。Be careful using complete mode with copy loops. 在解析复制循环后会删除模板中未指定的任何资源。Any resources that aren't specified in the template after resolving the copy loop are deleted.

资源类型处理完整模式删除的方式有所不同。There are some differences in how resource types handle complete mode deletions. 当父资源不在以完整模式部署的模板中时,将自动删除该资源。Parent resources are automatically deleted when not in a template that's deployed in complete mode. 而某些子资源不在模板中时,不会将其自动删除。Some child resources aren't automatically deleted when not in the template. 但是,如果删除父资源,则会删除这些子资源。However, these child resources are deleted if the parent resource is deleted.

例如,如果资源组包含 DNS 区域(Microsoft.Network/dnsZones 资源类型)和 CNAME 记录(Microsoft.Network/dnsZones/CNAME 资源类型),则 DNS 区域是 CNAME 记录的父资源。For example, if your resource group contains a DNS zone (Microsoft.Network/dnsZones resource type) and a CNAME record (Microsoft.Network/dnsZones/CNAME resource type), the DNS zone is the parent resource for the CNAME record. 如果使用完整模式部署并且模板中不包含 DNS 区域,则 DNS 区域和 CNAME 记录都将被删除。If you deploy with complete mode and don't include the DNS zone in your template, the DNS zone and the CNAME record are both deleted. 如果在模板中包含 DNS 区域但不包含 CNAME 记录,则不会删除 CNAME。If you include the DNS zone in your template but don't include the CNAME record, the CNAME isn't deleted.

有关资源类型如何处理删除的列表,请参阅针对完全模式部署的 Azure 资源删除For a list of how resource types handle deletion, see Deletion of Azure resources for complete mode deployments.

如果资源组被锁定,则完整模式不会删除资源。If the resource group is locked, complete mode doesn't delete the resources.


仅根级别模板支持完整部署模式。Only root-level templates support the complete deployment mode. 对于链接模板或嵌套模板,必须使用增量模式。For linked or nested templates, you must use incremental mode.

订阅级别部署不支持完整模式。Subscription level deployments don't support complete mode.

目前,门户不支持完整模式。Currently, the portal doesn't support complete mode.

增量模式Incremental mode

在增量模式下,资源管理器保留资源组中已存在但尚未在模板中指定的未更改资源 。In incremental mode, Resource Manager leaves unchanged resources that exist in the resource group but aren't specified in the template.

但是,以增量模式重新部署现有资源时,结果会有所不同。However, when redeploying an existing resource in incremental mode, the outcome is a different. 指定资源的所有属性,而不仅仅是要更新的属性。Specify all properties for the resource, not just the ones you're updating. 一个常见的误解是认为未指定的属性会保持不变。A common misunderstanding is to think properties that are not specified are left unchanged. 如果未指定某些属性,资源管理器会将更新解释为覆盖这些值。If you don't specify certain properties, Resource Manager interprets the update as overwriting those values.

示例结果Example result

为了说明增量模式和完整模式的差异,请考虑以下方案。To illustrate the difference between incremental and complete modes, consider the following scenario.

资源组包含:Resource Group contains:

  • 资源 AResource A
  • 资源 BResource B
  • 资源 CResource C

模板包含:Template contains:

  • 资源 AResource A
  • 资源 BResource B
  • 资源 DResource D

在“增量”模式下部署时,资源组具有: When deployed in incremental mode, the resource group has:

  • 资源 AResource A
  • 资源 BResource B
  • 资源 CResource C
  • 资源 DResource D

在“完整”模式下部署时,会删除资源 C。 When deployed in complete mode, Resource C is deleted. 资源组具有:The resource group has:

  • 资源 AResource A
  • 资源 BResource B
  • 资源 DResource D

设置部署模式Set deployment mode

在使用 PowerShell 部署时若要设置部署模式,请使用 Mode 参数。To set the deployment mode when deploying with PowerShell, use the Mode parameter.

New-AzResourceGroupDeployment `
  -Mode Complete `
  -Name ExampleDeployment `
  -ResourceGroupName ExampleResourceGroup `
  -TemplateFile c:\MyTemplates\storage.json

在使用 Azure CLI 部署时若要设置部署模式,请使用 mode 参数。To set the deployment mode when deploying with Azure CLI, use the mode parameter.

az group deployment create \
  --name ExampleDeployment \
  --mode Complete \
  --resource-group ExampleGroup \
  --template-file storage.json \
  --parameters storageAccountType=Standard_GRS

以下示例显示了设置为增量部署模式的链接模板:The following example shows a linked template set to incremental deployment mode:

"resources": [
      "apiVersion": "2017-05-10",
      "name": "linkedTemplate",
      "type": "Microsoft.Resources/deployments",
      "properties": {
          "mode": "Incremental",

后续步骤Next steps