This article describes the syntax you use to add a resource to your Bicep file. You're limited to 800 resources in a Bicep file. For more information, see Template limits.
Define resources
Add a resource declaration by using the resource keyword. You set a symbolic name for the resource. The symbolic name isn't the same as the resource name. You use the symbolic name to reference the resource in other parts of your Bicep file.
Symbolic names are case-sensitive. They may contain letters, numbers, and underscores (_). They can't start with a number. A resource can't have the same name as a parameter, variable, or module.
resource <symbolic-name> '<full-type-name>@<api-version>' = if (condition) {
<resource-properties>
}
To deploy more than one instance of a resource, use the for syntax. You can use the batchSize decorator to specify whether the instances are deployed serially or in parallel. For more information, see Iterative loops in Bicep.
Bicep
@batchSize(int)// optional decorator for serial deploymentresource <symbolic-name> '<full-type-name>@<api-version>' = [for <item> in <collection>: {
<properties-to-repeat>
}]
You can also use the for syntax on the resource properties to create an array.
Decorators are written in the format @expression and are placed above resource declarations. The following table shows the available decorators for resources.
Decorators are in the sys namespace. If you need to differentiate a decorator from another item with the same name, preface the decorator with sys. For example, if your Bicep file includes a parameter named description, you must add the sys namespace when using the description decorator.
BatchSize
You can only apply @batchSize() to a resource or module definition that uses a for expression.
By default, resources are deployed in parallel. When you add the batchSize(int) decorator, you deploy instances serially.
To add explanation, add a description to resource declarations. For example:
Bicep
@description('Create a number of storage accounts')resourcestorageAccountResources'Microsoft.Storage/storageAccounts@2023-04-01' = [forstorageNameinstorageAccounts: {
...
}]
Markdown-formatted text can be used for the description text.
Many resources require a location. You can determine if the resource needs a location either through intellisense or template reference. The following example adds a location parameter that is used for the storage account.
Different resource types are supported in different locations. To get the supported locations for an Azure service, See Products available by region. To get the supported locations for a resource type, use Azure PowerShell or Azure CLI.
az provider show \
--namespace Microsoft.Batch \
--query"resourceTypes[?resourceType=='batchAccounts'].locations | [0]" \
--out table
Resource tags
You can apply tags to a resource during deployment. Tags help you logically organize your deployed resources. For examples of the different ways you can specify the tags, see ARM template tags.
The preceding properties are generic to most resource types. After setting those values, you need to set the properties that are specific to the resource type you're deploying.
Use intellisense or Bicep resource reference to determine which properties are available and which ones are required. The following example sets the remaining properties for a storage account.