Configuring VSCode for ARM template development

Configuring VSCode for ARM template development

Visual Studio vs VSCode

Most sources of information around ARM template deployment (youtube videos, blogs etc) will demonstrate using Visual Studio to create and deploy templates. While Visual Studio will get the job done, keep in mind that Visual Studio is a tool for application development, and with that comes a bunch of bloat that we don't need and will never use when authoring ARM templates, such as:

  • All our template code must be contained within a solution. This creates a bunch of unnecessary files on disk that need to be excluded from source control.
  • When you use the IDE to deploy a template, it will execute a full build processs that creates more artifacts on disk in the /bin/debug directory. It will then execute a powershell script that will upload these artifacts to a storage account, and deploys them using a linked template deployment. Although it's great that the IDE abstracts this process from you, it does add an unnecessary layer of complexity to the deployment that makes it harder to troubleshoot when things go wrong.

All of this extras are unnecessary when working with ARM templates, after all, the meat of what we're doing is simply manipulating JSON files.

That being said however, the Visual Studio IDE does have a few cool features:

  • JSON Outline View
  • One-Click deployment
  • Source control integration

So if we're looking to move away from Visual Studio in order to eliminate the things that we don't like, it's important that whatever alternative we chose has feature parity with the features that we do like.

Enter VSCode

Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and macOS. What I like most about VSCode is that it's lightweight, cross platform, highly extensible and easy to customize. Because it is open source, there's a massive community around creating extensions to improve the functionality, and therefor the value, that we can leverage from using this tool.

Customizing VSCode

Before doing any kind of programming or coding, it is important to take the time to customize your development environment and tooling. The tools you use are the bridge between what's in your head and the manifestation of your awesomeness, so setting up your environment just the way you like it with everything you need available at your fingertips, is going to greatly aid in your success.

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe." - Abraham Lincoln

When using VSCode to create and deploy Azure Resource Manger templates, a few simple extensions, scripts, and keyboard shortcuts can rapidly speed up your development time.

Extensions

Extensions let you add languages, debuggers, and tools to your installation to support your development workflow.

Extensions can be installed by clicking the Extensions icon on the navigation bar (or CTRL + SHIFT + X), and typing in the search box in order to search the extension marketplace.

I consider the Azure Resource Manager Tools and Powershell extensions for VSCode mandatory for creating and deploying ARM templates.

For more information on extensions, see: VSCode Extension Marketplace documentation

Azure Resource Manager Tools

The Azure Resource Manager Tools extension adds intellisense for ARM templates, code peek for parameter and variable definitions, and much, much more. However my favorite part of this extensions is that it adds incredibly useful code snippets to help rapidly build out templates.

arm-snippit

Download Azure Resource Manager Tools Extension

There are some additional steps needed to install the ARM snippets. Make sure to follow the instructions.

Powershell

The Powershell extension add rich PowerShell language support for Visual Studio Code. It also adds support for intellisense, code snippets and the VSCode debugger. I find this extension invaluable for creating and deploying ARM deployment Powershell scripts and Pester tests.

Download Powershell Extension

Code Outline (optional)

Although the Code Outline extension is optional, some people may choose to use this extension if they made use of the the JSON Outline view in Visual Studio. I don't use this extension myself, however with it installed we now have a complete replacement for Visual Studio as our ARM development IDE.

Download Code Outline Extension

Make it pretty

Ask any UI developer, and they'll tell you that there is a science behind the aesthetics of an interface. From the size and shape of icons, to the colors used in the palate, all the way down to the typography, can have an effect on the mood (for better or for worse) of the end user.

Like I said earlier, you're going to be spending a lot of time inside VSCode, so its worth while taking the time to set it up in a way that is pleasing to you visually. Here are my tips to giving VSCode a fresh coat of paint.

Pick a theme

Using the keyboard shortcut CTRL + K, CTRL + T will bring up the theme picker. Maybe the PowershellISE is more your style?

VSCode comes with a nice selection of built in themes, but there are many more available on the extension marketplace.

Personally, i'm a fan of the One Dark Pro theme , so i'm going to go with that one.
atomtheme-1

Pick some icons

Install an icon pack from the extension gallery the same way as extensions and themes.
I like the Material Icon Theme, so that's going to be my choice.

icons

Change the font

The default font will do just fine for staring at for hours on end, but the best part about VSCode's extensibility is that everything can be customized - including the font.

Open the user settings with CTRL + , and add the following line to the settings.json

"editor.fontFamily": "FontName"

You can use any font installed on your system, as demonstrated below.

Your changes will take effect as soon as you save your settings. (CTRL + S)

Wingdings is recommended for masochists only.

The best thing is, you're not limited to standard Windows fonts.
I came across a font called Hack that I really like, so I downloaded it, installed it into my Windows font directory, and simply updated my settings.json to use it. While i'm in there messing with the font settings, I added a few additional personal touches.

Dial it in

At this point we're pretty much ready to go. I've just used the settings.json to change the behavior of a few additional things so it acts more towards my liking. These are simply quality of life changes that suit my personal preferences.

{
    // Theme/Display settings
    "workbench.colorTheme": "One Dark Pro Vivid",
    "editor.fontFamily": "Hack",
    "editor.fontSize": 14,
    "editor.fontLigatures": true,
    "window.zoomLevel": 0,

    // VSCode Settings
    "editor.formatOnSave": false,
    "editor.tabCompletion": true,
    "git.confirmSync": false,
    "git.enableSmartCommit": true,

    // Console settings
    "powershell.integratedConsole.focusConsoleOnExecute": false,
    "powershell.developer.editorServicesLogLevel": "Verbose",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
}

Conclusion

VSCode is a fantastic lightweight editor for just about any mainstream language, where it's real power comes from being able to customize it with an incredible degree of granularity.

In this post, i've shown you how to take a fresh install of a simple editor, and transform it into a fully functional replacement to Visual Studio int the context of authoring ARM templates - and we're just scratching the surface of what VSCode can do!

Learn More

I suggest taking the time to learn more about customizing VSCode. There are some great tips and tricks on the VSCode github page. Alsokeep a print out of the keyboard shortcuts somewhere close by. If you start to follow my blog, you're gonna need em'!