Using Bicep Linter Rules to control allowed resource API versions

Freek Berson
3 min readMay 24, 2023

--

Linter rules are a very powerful feature of the Bicep Infrastructure as Code language for Azure. Based on Linter rules, you can check your Bicep templates for syntax errors and best practice violations. Complying with coding standards improves your overall Bicep template quality.

Linter rules were introduced in version 0.4. That already seems like ages ago, but I remember that release coming out as I was working on my Bicep book at the time.

3 weeks ago, Bicep version 0.17.1 was released. Amongst other features and improvements, this version also introduces a new linter rule update. MaxAgeInDays configuration is now added to be used with the use-recent-api-versions linter rule.

The property does what it says, the property MaxAgeInDays allows you to specify how old (how many days) an API version is allowed to be in order to be able to use it. This allows you to put restrictions on the maximum age of API versions in your code. It is always recommended to use the most recent API versions for your resource declarations, but sometimes you might need to allow older API versions, or you might want to enforce a certain API age.

Time to upgrade! The easiest way to upgrade is to run the following command:

az bicep upgrade

The sample below shows how to use the new property.

Simply add the maxAllowedAgeInDays property to your use-recent-api-versions linter rule and provide the number of days as an integer. The default value is 730 days, which is equal to 2 years.

Providing a 0 means the apiVersion must be the latest (non-preview) version, or the latest preview version if there are only previews versions available at that point in time.

Based on the level of the linter rule, a Bicep Template using an ‘oudated’ API version will now get a warning as shown below which still allows you to build the template.

Or an error as shown below, which prevents you from building the template.

The flexibility to be able to configure the allows API versions is a great asset in your Bicep toolbox!

p.s. Microsoft Bing Image Creator Powered by Dall-E created the header image by simply asking “Bicep combined with computer programming”, how cool is that!?

--

--

Freek Berson

Empowering hybrid and remote workforces with a digital workspace from any device, anywhere. EUC Enthusiast, Microsoft MVP, 🎤 public speaker, 📚 Author.