Tutorial: Add a resource to your ARM template
In the previous tutorial, you learned how to create a blank Azure Resource Manager template (ARM template) and deploy it. Now, you're ready to deploy an actual resource. In this tutorial, you add a storage account. It takes about 9 minutes to complete this tutorial.
Prerequisites
We recommend that you complete the introductory tutorial about templates, but it's not required.
You must have Visual Studio Code with the Resource Manager Tools extension, and either Azure PowerShell or Azure CLI. For more information, see template tools.
Add resource
To add a storage account definition to the existing template, look at the highlighted JSON in the following example. Instead of trying to copy sections of the template, copy the whole file and replace your template with its contents.
Replace {provide-unique-name} and the curly braces {} with a unique storage account name.
Important
The storage account name must be unique across Azure. The name must have only lowercase letters or numbers. It can be no longer than 24 characters. You might try a naming pattern like using store1 as a prefix and then adding your initials and today's date. For example, the name you use could look like store1abc09092019.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-04-01",
"name": "{provide-unique-name}",
"location": "eastus",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
Guessing a unique name for a storage account isn't easy and doesn't work well for automating large deployments. Later in this tutorial series, you'll use template features that make it easier to create a unique name.
Resource properties
You may be wondering how to find the properties to use for each resource type. You can use the ARM template reference to find the resource types you want to deploy.
Every resource you deploy has at least the following three properties:
type: Type of the resource. This value is a combination of the namespace of the resource provider and the resource type such asMicrosoft.Storage/storageAccounts.apiVersion: Version of the REST API to use for creating the resource. Each resource provider publishes its own API versions, so this value is specific to the type.name: Name of the resource.
Most resources also have a location property, which sets the region where the resource is deployed.
The other properties vary by resource type and API version. It's important to understand the connection between the API version and the available properties, so let's jump into more detail.
In this tutorial, you added a storage account to the template. You can see that API version at storageAccounts 2021-04-01. Notice that you didn't add all of the properties to your template. Many of the properties are optional. The Microsoft.Storage resource provider could release a new API version, but the version you're deploying doesn't have to change. You can continue using that version and know that the results of your deployment will be consistent.
If you view an older API version, such as storageAccounts 2016-05-01, you'll see that a smaller set of properties are available.
If you decide to change the API version for a resource, make sure you evaluate the properties for that version and adjust your template appropriately.
Deploy template
You can deploy the template to create the storage account. Give your deployment a different name so you can easily find it in the history.
If you haven't created the resource group, see Create resource group. The example assumes you've set the templateFile variable to the path to the template file, as shown in the first tutorial.
New-AzResourceGroupDeployment `
-Name addstorage `
-ResourceGroupName myResourceGroup `
-TemplateFile $templateFile
Note
If the deployment failed, use the verbose switch to get information about the resources being created. Use the debug switch to get more information for debugging.
Two possible deployment failures that you might encounter:
Error: Code=AccountNameInvalid; Message={provide-unique-name}is not a valid storage account name. Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.In the template, replace
{provide-unique-name}with a unique storage account name. See Add resource.Error: Code=StorageAccountAlreadyTaken; Message=The storage account named store1abc09092019is already taken.In the template, try a different storage account name.
This deployment takes longer than your blank template deployment because the storage account is created. It can take about a minute but is usually faster.
Verify deployment
You can verify the deployment by exploring the resource group from the Azure portal.
- Sign in to the Azure portal.
- From the left menu, select Resource groups.
- Select the resource group you deployed to.
- You see that a storage account has been deployed.
- Notice that the deployment label now says: Deployments: 2 Succeeded.
Clean up resources
If you're moving on to the next tutorial, you don't need to delete the resource group.
If you're stopping now, you might want to 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.
- Select Delete resource group from the top menu.
Next steps
You created a simple template to deploy an Azure storage account. In the later tutorials, you learn how to add parameters, variables, resources, and outputs to a template. These features are the building blocks for much more complex templates.
Povratne informacije
Pošalјite i prikažite povratne informacije za