The third part of the Bicep series explains the two forms of the `for` expression for declaring many similar resources from a single block, plus index access and controlling deployment parallelism with `@batchSize`. It also shows conditional resources through `if` and the ternary operator.
Key points
- `for name in array` iterates a list; `range(start, count)` fits cases where only a number of instances is known.
- The `(name, i)` syntax yields both the element and its index, e.g. `storageAccounts[i].name` in outputs.
- The `@batchSize(1)` decorator deploys instances sequentially instead of in parallel, useful for rate limits.
- An `if (condition)` prefix creates a resource or module only when the condition evaluates to true.
- Single values use the ternary operator, as in `environment == 'prod' ? 'Standard_GRS' : 'Standard_LRS'`.
Real-world use
- A template that declares several storage accounts for different teams
- A row of subnets inside a virtual network that must be created in order
- A backup storage account that is provisioned only in production
- Test scenarios where resources with strict API rate limits must be deployed sequentially
This summary was generated by the agent from the original post on dotnetpro (de). The full text and all rights belong to its author and publisher. Go to original