No more JSON Parameter files!?
Well, nearly. The .bicepparam feature is still in experimental mode currently, but looks to be coming soon as part of the future Bicep releases.
If you’ve worked on ARM templates or Bicep you will be very familiar with the joys of working with a JSON parameters file. It can be painful, tedious and cumbersome.
So what will the new feature bring? The beauty of bicepifying the parameter file!
How to enable the .biceppram feature on?
Make sure you’ve updated your Bicep to at least release v0.16.1 as per Release v0.16.1 · Azure/bicep · GitHub & have the Bicep VSCode Bicep extension installed.
The new bicepparam feature has now gone GA: Create parameters files for Bicep deployment – Azure Resource Manager | Microsoft Learn
Make sure you have upgraded to the latest bicep version. The rest of the guide is still relevant.
az bicep upgrade
az bicep version
Now we’re on the latest bicep release, we need to enable the experimental feature using the bicepconfig.json file like so:
If you’ve not got a bicepconfig.json file you can create one by following the official documentation for a step-by-step guide.
How to use the .bicepparam file?
Once all the above has been enabled we can start using .bicepparam in VSCode!
- Create your file.bicepparam
Then you’ll need to specify the main bicep file you want it to reference:
using 'main.bicep'
And just like the JSON parameters, you can reference them in this file by in a more Bicep friendly manner, as an example:
prod.bicepparam:
using 'main.bicep'
param orgPrefix = 'rios'
param regionSh = 'uks'
param location = 'uksouth'
param tags = {
Demo: 'Demo'
Owner: 'Dan Rios'
Env: 'Dev'
}
main.bicep:
targetScope = 'subscription'
// Resource Group Params
param orgPrefix string
param regionSh string
param location string
param tags object
resource rg ''Microsoft.Resources/resourceGroups@2021-04-01' = {
name: 'rg-demo'
params:{
parLocation: location
parResourceGroupName: 'rg-${orgPrefix}-${regionSh}-demo'
parTags: tags
}
}
How to deploy?
In Azure CLI:
az login
az account show --output table
az account set --subscription "SubscriptionName"
az deployment sub what-if -l uksouth -f .\main.bicep -p .\prod.bicepparam
az deployment sub create -n 'deployRG' -l uksouth -f .\main.bicep -p .\prod.bicepparam
What-If shows us that the resource group will be deployed:
Now we’re happy knowing what is about to deploy we can switch to the create cmdlet to proceed – all done!
"provisioningState": "Succeeded",
"templateHash": "13799875250777117000",
"templateLink": null,
"timestamp": "2023-04-17T19:29:45.782399+00:00",
"validatedResources": null
},
Goodbye JSON params!
Although this is still an experimental feature, so subject to change I’m sure it’s much nicer to use the parameter file with it being now aligned to the Bicep language. It’s easy to use, intuitive and looks nicer to read.
That will be especially important when the files are large, which is where JSON param files can be a bit of a mess to read over. Bring on the official release!
Hi Dan,
Great info. Do you have any idea when this will come to the MS hosted agents? Or where we can see what the status is?
Thanx!
Hey,
Thank you!
The release is scheduled for this month by the Bicep team – Bicep release v0.18. So it should work then with Azure CLI task in your agent. If not, you can probably use it now as long as your bicepconfig.json is correct. May be of use: https://youtu.be/7l6IiMCukwo?t=75 and https://github.com/orgs/Azure/projects/115/views/35
I am developing my first Bicep deployment template, and loving it so far. I have a question, though… There doesn’t appear to be support (at least, not yet) in the .bicepparam file for a parameter that is only used to support another parameter in the .bicepparam file, and not in the main.bicep file.
For example:
param owner_name = ‘Daffy Duck’
param environment_name = ‘test’
param resourceTags = {
Environment: environment_name
‘Application Owner’: owner_name
‘CREATED-BY’: owner_name
}
The message I am getting is in the main.bicep file, “Parameter ‘owner_name’ is declared but never used.’
If I leave it out of the main.bicep file, then I get an error in the .bicepparam file.
Looks that may be the case. They have quite a few sample parameter examples on the docs here that may be useful: https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/parameter-files?tabs=Bicep
I used it and rolled right back to json because of jsonloadtext instead of passing parameter from main to module to submodules. Error in one parameter lead to fix in four place.
Hopefully, there will option target with Mutiple param file or even use json() to extract live while coding by passing it to the object variable