title: Create multiple resource instances using Azure Resource Manager | Microsoft Docs description: Learn how to create an Azure Resource Manager template to create multiple Azure resource instances. services: azure-resource-manager documentationcenter: '' author: mumian manager: dougeby editor: tysonn
ms.service: azure-resource-manager ms.workload: multiple ms.tgt_pltfrm: na ms.devlang: na ms.date: 11/13/2018 ms.topic: tutorial ms.author: jgao
Learn how to iterate in your Azure Resource Manager template to create multiple instances of an Azure resource. In this tutorial, you modify a template to create three storage account instances.
[!div class="checklist"]
- Open a QuickStart template
- Edit the template
- Deploy the template
If you don't have an Azure subscription, create a free account before you begin.
To complete this article, you need:
Azure QuickStart Templates is a repository for Resource Manager templates. Instead of creating a template from scratch, you can find a sample template and customize it. The template used in this quickstart is called Create a standard storage account. The template defines an Azure Storage account resource.
-
From Visual Studio Code, select File>Open File.
-
In File name, paste the following URL:
https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json
-
Select Open to open the file.
-
There is a 'Microsoft.Storage/storageAccounts' resource defined in the template. Compare the template to the template reference. It is helpful to get some basic understanding of the template before customizing it.
-
Select File>Save As to save the file as azuredeploy.json to your local computer.
The existing template creates one storage account. You customize the template to create three storage accounts.
From Visual Studio Code, make the following four changes:
- Add a
copy
element to the storage account resource definition. In the copy element, you specify the number of iterations and a variable for this loop. The count value must be a positive integer and can't exceed 800. - The
copyIndex()
function returns the current iteration in the loop. You use the index as the name prefix.copyIndex()
is zero-based. To offset the index value, you can pass a value in the copyIndex() function. For example, copyIndex(1). - Delete the variables element, because it is not used anymore.
- Delete the outputs element. It is no longer needed.
The completed template looks like:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[concat(copyIndex(),'storage', uniqueString(resourceGroup().id))]",
"apiVersion": "2018-02-01",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "Storage",
"properties": {},
"copy": {
"name": "storagecopy",
"count": 3
}
}
]
}
For more information about creating multiple instances, see Deploy multiple instances of a resource or property in Azure Resource Manager Templates
Refer to the Deploy the template section in the Visual Studio Code quickstart for the deployment procedure.
To list all three storage accounts, omit the --name parameter:
echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az storage account list --resource-group $resourceGroupName
$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName
Compare the storage account names with the name definition in the template.
When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.
- From the Azure portal, select Resource group from the left menu.
- Enter the resource group name in the Filter by name field.
- Select the resource group name. You shall see a total of six resources in the resource group.
- Select Delete resource group from the top menu.
In this tutorial, you learned how to create multiple storage account instances. So far, you have created one storage account or multiple storage account instances. In the next tutorial, you develop a template with multiple resources and multiple resource types. Some of the resources have dependent resources.
[!div class="nextstepaction"] Create dependent resources