Skip to main content

Deploying a resource group via parameter

In this guide, we'll walk through the steps to deploy a resource with a parameter file in Azure using Bicep.

info

Rather than passing parameters as inline values in your script, you can use a Bicep parameters file with the .bicepparam file extension that contains the parameter values.

A single Bicep file can have multiple Bicep parameters files associated with it. However, each Bicep parameters file is intended for one particular Bicep file. This relationship is established using the using statement within the Bicep parameters file.

So in short you create 1 deployment file and use multiple parameter files to deploy several resources in one go.

Create a bicep file

Open Visual Studio Code in the C:\DTX-IaC-Demo folder and copy the resourcegroup-networking.bicep to a new file with the name resourcegroup.bicep.

  • Select the file resourcegroup-networking.bicep in the explorer
    VSCode copy file 01
  • Press CTRL-C to copy the file
  • Press CTRL-V to paste the file
    VSCode copy file 02
  • Rename the file to resourcegroup.bicep by selecting the file resourcegroup-networking copy.bicep and pressing F2
    VSCode copy file 03

We can now reuse the resourcegroup.bicep file to deploy the resource group.

Create the parameter file

Visual Studio Code has a nice feature to create a parameter file for a bicep file.

  • Select the resourcegroup.bicep file and right click, choose Generate Parameters File
    VSCode bicep param 01
  • Output format: bicepparam
  • Parameters: all

A .bicepparam file is created with the name resourcegroup.bicepparam and should look like this:

using './resourcegroup.bicep'

param location = 'westeurope'
param name = 'rg-networking'

We can now create several parameter files for the different resources we want to deploy, and reuse this template in other modules.
Line 1 points to the bicep file we want to use, and line 3 and 4 are the parameters we want to use in the bicep file.

We can now create some new parameters files to create the resource groups we need later on:

  • Copy the resourcegroup.bicepparam file to a new file with the name resourcegroup-002.bicepparam.
    • Set the name for the resource group to rg-virtualmachine
  • Copy the resourcegroup.bicepparam file to a new file with the name resourcegroup-003.bicepparam.
    • Set the name for the resource group to rg-monitoring

Deploy all the parameter file

foreach ($parameterFile in Get-ChildItem -Path . -Recurse -Filter 'resourcegroup*.bicepparam') { $paramFilePath = $($parameterFile.Name).Replace("\", "/"); az deployment sub create --parameters $paramFilePath --location westeurope }
info

This script will loop through all the parameter files that start with the name resourcegroup and have file extension of .bicepparam in the current folder and deploy the resources to the subscription.
The file found are deployed to the location westeurope.

Template

Your parameter file resourcegroup-002.bicepparam should look like this:

using './resourcegroup.bicep'

param location = 'westeurope'
param name = 'rg-virtualmachine'

Version overview

This document has the following versions:

VersionDateOverview of changes
1.12024-03-18Updated the document.
1.02024-03-06Initial version.