How to Create Multiple Storage Accounts on Azure Using Bicep Loops

Do you need to create multiple Azure storage accounts? Are you looking for an easy way to do it? If so, then Bicep Loops is the answer for you!

Bicep Loops is a handy tool that makes it easy to create and manage Azure storage accounts. In this tutorial, we will show you how to use Bicep Loops to create multiple storage accounts on Azure. Let’s get started!

Azure Bicep Loops makes it easy to create multiple Azure resources. In this tutorial, we will show you how to use Azure Bicep Loops to create four storage accounts.

Loops (Count)

Azure Bicep offers a few types of loops, and today we will focus on a loop based on a count. In practice, we tell Bicep how many resources to create from the same type, and it will create them.

We use a for loop with a range function to create a count loop, as shown below.

[for i in range(1,4):]

Template

The template below creates four storage accounts with random names.

param location string = resourceGroup().location
param utc string = utcNow()

var storageaccountname  = 'ntweekly${uniqueString(utc)}'

resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = [for i in range(1,4): {
  name: '${storageaccountname}${i}'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}]

The result is shown below.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.