top of page
Search
  • Writer's pictureShannon

Noodling with Bicep

Now that I have your attention, know I've started digging into Bicep. It only makes sense, as I'm pretty deep into ARM Templates and generally believe automation can solve most problems that exist within the IT ecosystems in the wild. Turns out taking existing ARM Templates and transforming them into Bicep templates is relatively easy, but not without hiccups. Even the hiccups aren't as bad as I originally envisioned. Yes, even I can have Azure fatigue sometimes: "Oh, a new thing to learn? Let's put that on the back burner with literally everything else I don't have time for."


There's a forcing function behind why I wanted to dig deeper with Bicep and it literally has to do with my video series I'm co-hosting with Matt Canty + a separate task that will hopefully show up on a work blog. Stay tuned for both!


First off, Bicep is Microsoft's new declarative template syntax language for provisioning resources in Azure. Prior to Bicep, ARM Templates were the go-to for Azure only infrastructure buildout. Note, you can always use Terraform, however Terraform is not tied only to Azure. Terraform is multi-cloud and on-premises (which reminds me - I need to dabble with the on-premises providers...note to self!).


Between the Bicep documentation and the Microsoft Learn Path, I had more than enough to get started. On top of this, I never have a problem failing at deploying resources, as it teaches you even further in an on-the-fly fashion.


If you're like me, you probably have a number of ARM Templates you've built over the years. Translating them to Bicep surprisingly isn't painful. There is a decompile command you issue with the AZ-CLI syntax that takes any ARM Template and "best guesses" what the Bicep template would use. The yellow warning text highlights that information for you when you run the command:

Additionally, you may see red text:

Between the warnings and errors, I reached out to a colleague of mine for additional help on how I should be fixing these issues (THANKS, Matt Davis!). He mentioned I should trust the linter in Visual Studio Code to fix errors and warnings. Between the Microsoft Learn path, the Microsoft documentation, and the linter, that should get you most of the way there related to deploying resources in Azure.


So what's the linter? A lint or linter is a "tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs." The Bicep extension can be found in the Visual Studio Code marketplace. Ensure you install that within your local programming environment. Additionally, if you're setting this up for the first time, make sure you give this document a once over to ensure you're well on your way.


When you open up the Bicep with the errors, hover over any error and you should see helpful information show up in the linter that guides you toward fixing the problem. In the example below, I even have a quick fix (which speeds up this process pretty significantly):

Once you fix all errors and examine the warnings, you have a Bicep file to use! SWEET!


Next, browse out to that directory and run a simple AZ-CLI command or a PowerShell command to deploy the resource (note the parameters JSON file you may be comfortable using with ARM Templates is still the same file you'll use for Bicep deployments - at least right now):

$rgName = "bicep-testing"
$location = "eastus"
$tmplFileBicep = "C:\Users\shkuehn\bicep\azuredeploy.bicep"
$tmplParamFileBicep = "C:\Users\shkuehn\bicep\azuredeploy.parameters.json"

New-AzResourceGroup -Name $rgName -Location $location -Verbose
New-AzResourceGroupDeployment -Name AVSDeployment `
-ResourceGroupName $rgName -TemplateFile $tmplFileBicep `
-TemplateParameterFile $tmplParamFileBicep -Verbose

The verbose flag in both instances is something I always recommend. You will get an indication if anything fails + why it failed that way first. Then you can browse out to the Activity Log within the resource group for more information if the template failed. Just so you know, I received a number of failures throughout experimenting with Bicep, which tells me I need to keep digging and bettering myself throughout the process (I'll be sure to blog about learnings). I took a combination of the verbose messages + the Activity Log raw failure JSON to figure out what wasn't working right.


BUT BEFORE I EVEN ARRIVED AT AZURE PORTAL TROUBLESHOOTING, I received the following error message, time and time again:

Guess what I forgot to do? Update PowerShell (remember I'm a PowerShell nerd - sorry y'all). So in addition to getting your local environment sorted, ensure your PowerShell version is at the required version.


I use Chocolatey for all my Windows machines (even servers). I simply ran choco upgrade all -y, waited for all software to be updated, and I could run my Bicep template without issue.


My hope? That I may have saved you from diving super deep and troubleshooting failed deployment after failed deployment with Bicep. Also, this post will serve as a reminder whenever I get my computer refreshed into the future. Cheers!

Recent Posts

See All

Comments


bottom of page