ARM 模板是否会覆盖脚本创建的现有资源?
Does ARM template overwrite existing resource created by script?
我的 azure 帐户中有一个由脚本创建的 consomosDB,我想创建一个 ARM 模板以通过 ARM 模板管理资源部署,我如何确保 ARM 模板不会 recreate/overwrite 资源,因为它是第一次使用 ARM 模板部署?
要使用 ARM 模板修改现有资源,请从 Azure 门户中导出资源模板。然后下载到本地。然后,您可以修改它以更新 Cosmos 资源的设置。 ARM 模板有 api 个版本。这将与您用于创建 Cosmos 帐户的 PS 或 CLI 中的基础版本一致。修改 ARM 模板时,您需要记下 api 版本,然后参考该版本 Cosmos DB schema reference 以确保属性与您部署的模板中的 api 版本相匹配。
ARM 模板将不会 recreate/overwrite 现有资源,如果资源已在模板中指定。如果资源的 属性 值发生更改,它将更新资源。请参阅下面摘自 official document.
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.
In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template
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
因此,如果您希望现有资源保持不变,您可以从 Azure 门户导出资源模板,以确保所有属性都已指定且未更改。
您也可以锁定资源,将锁定级别设置为CanNotDelete或ReadOnly,以防止资源被删除或修改。查看文档 Lock resources to prevent unexpected changes 了解更多信息。
我的 azure 帐户中有一个由脚本创建的 consomosDB,我想创建一个 ARM 模板以通过 ARM 模板管理资源部署,我如何确保 ARM 模板不会 recreate/overwrite 资源,因为它是第一次使用 ARM 模板部署?
要使用 ARM 模板修改现有资源,请从 Azure 门户中导出资源模板。然后下载到本地。然后,您可以修改它以更新 Cosmos 资源的设置。 ARM 模板有 api 个版本。这将与您用于创建 Cosmos 帐户的 PS 或 CLI 中的基础版本一致。修改 ARM 模板时,您需要记下 api 版本,然后参考该版本 Cosmos DB schema reference 以确保属性与您部署的模板中的 api 版本相匹配。
ARM 模板将不会 recreate/overwrite 现有资源,如果资源已在模板中指定。如果资源的 属性 值发生更改,它将更新资源。请参阅下面摘自 official document.
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.
In complete mode, Resource Manager deletes resources that exist in the resource group but aren't specified in the template
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
因此,如果您希望现有资源保持不变,您可以从 Azure 门户导出资源模板,以确保所有属性都已指定且未更改。
您也可以锁定资源,将锁定级别设置为CanNotDelete或ReadOnly,以防止资源被删除或修改。查看文档 Lock resources to prevent unexpected changes 了解更多信息。