These days, I spend a lot of time working with Microsoft Azure. I also make a conscious effort to use the Azure CLI and Azure PowerShell module when managing my Azure resources. These resources help me get a better understanding of the platform and allow me to move freely between devices.
If we add Azure Resource Manager (ARM) templates on top of these tools, we can make provisioning and managing resources a much better experience. ARM templates also allow us to take full advantage of CI/CD processes for our infrastructure.
ARM templates are JSON files that describe a resource and related dependencies. These files can sometimes be large and complicated; as such, a good editor is important. Recently, I learned that Visual Studio Code, the new, lightweight, open-source, cross-platform code editor from Microsoft has added support for creating and editing ARM templates through a new extension.
VScode and the extension
Let’s have a look at what’s required to use VScode to develop ARM templates.
- Download and install Visual Studio Code for your platform
- Launch VS Code
- Open Quick Open (Ctrl+P)
- Type
ext install azurerm-vscode-tools
and hit Enter
Install snippets for more power
I came across a nice set of snippets that are provided by the Azure Cross-Platform Tooling Samples. I do not doubt that these will make your life much better. However, Azure doesn’t have a nice plugin available that will automatically install the snippets (yet), so we need to perform some manual steps.
- Browse to the snippets file on Github and copy to clipboard
- Inside VScode, navigate to
File > Preferences > User Snippets > JSON
- Append the contents into your user snippets before the final
}
- Save and close the snippets file
Hack on ARM templates
The easiest way to start hacking is to grab one of the Quick Start Templates that are available on Github.
If you open 100-blank-template/azuredeploy.json
, you should see something like:
To add resources to the template, go to "resources": [
, and hit Enter. Now, when you start typing arm
, you should be presented with the snippet list.
If we click arm-ip
the snippet will add the resource for us.
If you have any schema validation issues in your template, VScode will show squiggles inline in the editor. You can also view the list of errors and warnings by hitting Ctrl/Command+Shift+M or by clicking the glyphs in the lower-left status bar.