Azure Bicep - Deploy Mutliple Resource Groups in same Template

Son 311 Reputation points
2024-01-15T15:15:43.5833333+00:00

Hi, I am new to Bicep and trying to use it to deploy a new environment I am configuring for one of our businesses. I'd like to get to the point where I can just deploy the file and away it goes and deploys as much of the environment as possible:

  • Multiple resources groups
  • VNet gateway
  • Public IP
  • x2 Virtual Machines

etc.

I am however falling over at the first hurdle, I am able to deploy a single resource group in the .bicep file but as soon as I try deploying two, VS code is complaining that I cannot deploy more than one. Is there a way round this?

targetScope = 'subscription'
@description('Name of the resource group to create.')
param rgName string = 'rg-vnetwork-01'
param rgName1 string ='rg-routetables-01'
@description('Azure Region the resource group will be created in.')
param rgLocation string = 'uksouth'
resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = {
  name: rgName
  location: rgLocation
}
resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = {
  name: rgName1
  location: rgLocation
}

When I try this VS Code is showing the following:

"Identifier "resourceGroup" is declared multiple times. Remove or rename the duplicates."

Hope someone can help.

Thanks

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,175 questions
Azure Resource Mover
Azure Resource Mover
An Azure service used for moving multiple resources between Azure regions.
224 questions
{count} votes