Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ARM template overwrite existing resource created by script?

I have a consomosDB in my azure account created by a script, I want to create an ARM template to manage the resource deployment by ARM template going forward, how can I make sure that ARM template doesn't recreate/overwrite the resource as it is the first time going to be deployed using ARM template?

like image 289
mehran Avatar asked Sep 20 '25 22:09

mehran


2 Answers

ARM template willnot recreate/overwrite the existing resource, if the resource is specified in the template. It will update the resource if the property values for a resource are changed. See below extract from the 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

So if you want the existing resource remain intact, you can export the resource template from Azure Portal to make sure all the properties are specified and not changed.

You can also lock the resource, set the lock level to CanNotDelete or ReadOnly to keep the resource from deleted or modified. Check document Lock resources to prevent unexpected changes for more information.

like image 80
Levi Lu-MSFT Avatar answered Sep 22 '25 12:09

Levi Lu-MSFT


To modify existing resources using ARM templates, export the template for the resource from within the Azure Portal. Then download it locally. You can then modify it to update settings for Cosmos resources. ARM templates have api-versions. This will coincide with the underlying version in PS or CLI that you used to create the Cosmos account. When modifying the ARM template you will need to note the api-version and then refer to that version Cosmos DB schema reference to ensure the properties match the api-version in the template you deployed.

like image 44
Mark Brown Avatar answered Sep 22 '25 11:09

Mark Brown