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 difference between these two modes is how Resource Manager handles existing resources in the resource group that aren't in the template.

对于这两种模式,资源管理器都会尝试创建模板中指定的所有资源。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.

默认模式为增量模式。The default mode is incremental.

完整模式Complete mode

在完整模式下,资源管理器删除资源组中已存在但尚未在模板中指定的资源 。In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template.


在完全模式下部署模板之前,请始终使用 what-if 操作Always use the what-if operation before deploying a template in complete mode. 如果显示哪些资源将被创建、删除或修改。What-if shows you which resources will be created, deleted, or modified. 使用 what-if 以避免意外删除资源。Use what-if to avoid unintentionally deleting resources.

如果模板包含由于条件的计算结果为 false 而未部署的资源,则结果取决于用于部署模板的 REST API 版本。If your template includes a resource that isn't deployed because condition evaluates to false, the result depends on which REST API version you use to deploy the template. 如果使用 2019-05-10 之前的版本,则 不会删除 该资源。If you use a version earlier than 2019-05-10, the resource isn't deleted. 如果使用 2019-05-10 或更高版本,则 会删除 该资源。With 2019-05-10 or later, the resource is deleted. 最新版本的 Azure PowerShell 和 Azure CLI 会删除该资源。The latest versions of Azure PowerShell and Azure CLI delete the resource.

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

如果部署到模板中的多个资源组,则可以删除部署操作中指定的资源组中的资源。If you deploy to more than one resource group in a template, resources in the resource group specified in the deployment operation are eligible to be deleted. 辅助资源组中的资源不会被删除。Resources in the secondary resource groups aren't 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. 模板中的资源添加到资源组。Resources in the template are added to the resource group.


在增量模式下重新部署现有资源时,所有属性都将重新应用。When redeploying an existing resource in incremental mode, all properties are reapplied. 属性不会以增量方式添加The properties aren't incrementally added. 一个常见的误解是认为未在模板中指定的属性会保持不变。A common misunderstanding is to think properties that aren't specified in the template are left unchanged. 如果未指定某些属性,资源管理器会将部署解释为覆盖这些值。If you don't specify certain properties, Resource Manager interprets the deployment as overwriting those values. 未包含在模板中的属性将重置为默认值。Properties that aren't included in the template are reset to the default values. 指定资源的所有非默认值,而不仅仅是要更新的属性。Specify all non-default values for the resource, not just the ones you're updating. 模板中的资源定义始终包含资源的最终状态。The resource definition in the template always contains the final state of the resource. 它不能表示对现有资源的部分更新。It can't represent a partial update to an existing resource.

在极少数情况下,为资源指定的属性是作为子资源实现的。In rare cases, properties that you specify for a resource are actually implemented as a child resource. 例如,当为 Web 应用提供站点配置值时,会在子资源类型 Microsoft.Web/sites/config 中实现这些值。For example, when you provide site configuration values for a web app, those values are implemented in the child resource type Microsoft.Web/sites/config. 如果重新部署 Web 应用并为站点配置值指定了空对象,则子资源不会更新。If you redeploy the web app and specify an empty object for the site configuration values, the child resource isn't updated. 但是,如果提供新的站点配置值,则子资源类型会更新。However, if you provide new site configuration values, the child resource type is updated.

示例结果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 deployment group 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": [
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2020-10-01",
    "name": "linkedTemplate",
    "properties": {
      "mode": "Incremental",

后续步骤Next steps