I am new to ARM. I have created an ARM Template for deploying storage accounts and a data factory in a resource group.
If I want to use the same ARM Template to add another resource into the same resource group, can I not simply add that resource in the ARM Template below the storage accounts and data factory deployment code and run the ARM template?
Because currently, when I run the same template it is giving me an error saying:
storage accounts already exists.
Seems like it is trying to redeploy the storage accounts, which I don't want. How can I use the same ARM Template every time I have to deploy some new resource, by avoiding redeployment of already deployed resources?
Is there anything I can add in the ARM Template ?
Note: I don't wish to use PowerShell or Azure CLI here. I am deploying the resources using a pipeline where I have created YAML tasks.
PFB my sample template :
{
"$schema": "http://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "West Europe"
},
"storageAccountName": {
"type": "string",
"defaultValue": "storageabc"
}
"accountType": {
"type": "string"
},
"kind": {
"type": "string"
}
...
},
"resources": [
{
"name": "[parameters('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"location": "[parameters('location')]",
"properties": {},
"dependsOn": [],
"sku": {
"name": "[parameters('accountType')]"
},
"kind": "[parameters('kind')]"
},
{
"type": "Microsoft.DataFactory/factories,
"apiVersion": "2018-06-01"
-
-
-
..
}
],
"outputs": {}
}
Storage account names have to be globally unique. Perhaps someone had already use that name, hence the message.
Common pattern is to use uniqueString(resourceGroup().id) function to reduce the probability of a clash.
If you are sure this name is unique, make sure you redeploy to this same resource Group and subscription. If you try to do a redeploy to a different resource group or subscription, Azure will try to create new resources and will throw you an error like you receive.
Template deployments are scoped, so if you change the scope (in this case resource group), you will get a new set of resources based on this template. For resources which names must be unique among entire Azure (i.e. storage account or container registry, web app, function app, etc.) best practice is to use hash based on the resource group id. The I’d contains guid of the subscription, which Azure makes sure is unique, so the probability of a clash is very low.