Deploy Bicep/ARM using Containers

Developing using containers offers the ability to use different environments and software without having to install them on your development workstation, while at the same time you conserve a lot of system resources avoiding the use of virtual machines. Visual Studio Code has been receiving a lot of functionality towards that end with a great deal of extensions and part of that is targeting Azure template developement. 

We can use VS Code to develop our code and then use a container with all the Azure tools to deploy. This post describes this very process, from docker installation to VS Code configuration and finally template deployment. 

First we need to install all the necessary components on our system. This includes Docker Desktop, Visual Studio Code and a patch for the linux kernel of Windows Subsystem for Linux (WSL 2).

You can find Docker Desktop on the official Docker page here and VS Code on its page over here. The Docker installation wizard will add any required Windows features to your machine, so there's no reason to worry about that. The only thing that you'll have to manually install is the WSL 2 patch that you can get from here. We don't need anything special here so use the default installation options.

Next, we need to configure VS Code with a couple of Docker extensions. Open VS Code, switch to the extensions page and install "Docker" and "Remote - Containers" just like below (hover to animate):

To make things easier with the templates that we're going to create, you can also install the Bicep and/or ARM extensions. In this post, we're going to develop and deploy a Bicep file.

After you open the folder that contains the template file (or your project), you'll have to add a container configuration to your project. Open the Command Pallete and search for "Remote-Containers: Add" to get the command to add development container configuration. In this case I'm using the Azure Bicep community image with .Net Core 3.1. If you're deploying ARM you can use the Azure CLI image.

As soon as the configuration is added, VS Code will prompt you to re-open the workspace but this time it will be in the container. This will start the container build process that may take a while.

VS Code will now create new objects that appear on the docker console, including an image, a container based on that image, and a volume.

The container is the system that we are going to be using to run our Azure commands:

This container will be based on the image the we have selected earlier:

The volume that will be created is the way for the container to access the files in our project folder stored on our workstation:

When the container is configured, you can start a new terminal and connect directly to it (hover to animate):

From this point on, the deployment process is exactly the same as if you were using Azure CLI on your machine. You just connect to your Azure account and deploy the template (hover to animate):

That pretty much how you can develop Bicep and ARM on your machine and use Azure CLI on a container to perform the deployment!

Popular posts from this blog

Configuring a Certificate on Exchange Receive Connector

IIS Client Certificate Revocation Check Disable

Send Syslog Messages from PowerShell