Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
Cloud Computing

Using VS Code to Edit Azure JSON Templates

json-hero

What tools should you use to edit Azure JSON templates? I’ll show you how to get started with the tool that I recommend – VS Code.

Getting Started with VS Code

Microsoft has a free and open-source, stripped down version of Visual Studio called VS Code. VS Code doesn’t have some of the fancy GUI and deployment options of Visual Studio, but VS Code makes for a great JSON editor, especially when you add a few Azure JSON extensions.

 

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

 

The Windows installer download is just over 32MB (at the time of writing), and it’s a simple next-next-next routine, which differs greatly from my last, confusing, experience with Visual Studio. When you open VS Code for the first time it has basic functionality, such as IntelliSense, code validation, and formatting to fix up all that annoying indentation that makes the template readable.

Add Azure Resource Manager Tools Extension

VS Code doesn’t understand Azure JSON to begin with, so you need to add an extension to add JSON functionality. A marketplace of extensions exists for VS Code; these extensions include Microsoft-written extensions and others from interested third-parties, including community and business offerings.

To add support for Azure Resource Manager (ARM) templates, do the following in VS Code:

  1. Press CTRL+P to open Quick Open.
  2. Run the following command: ext install azurerm-vscode-tools.
  3. An extension called Azure Resource Manager Tools will be found in the marketplace. Click Install to install this extension in VS Code.
  4. Click Reload when prompted to restart VS Code with the new extension enabled.

Installing the Azure Resource Manager Tools extension in VS Code [Image Credit: Aidan Finn]
Installing the Azure Resource Manager Tools extension in VS Code [Image Credit: Aidan Finn]
Tip: When you start a new file in VS Code, the tool has no idea what you’re doing, so save the file in the right format as soon as you can so that VS Code can start to help you.

jsonvscode

This extension adds a lot of functionality that I like:

  • IntelliSense for advanced features such as properties of the resourceGroup() or subscription() functions.
  • Pressing F2 to rename all instances of a highlighted piece of code.
  • Warnings for unused variables or parameters, highlighting items to remove or items you’ve forgotten to use in resources.

Set Up ARM Snippets

VS Code doesn’t have the pretty UI for adding resources to a template that you’ll get in the paid-for Visual Studio, but you can get this functionality via IntelliSense – you simply start typing the resource type, select an option, and VS Code fills out the framework required to deploy that resource. For example, if I type “arm” in an empty Resources section, a menu appears and I can select a snippet for lots of resource types. If I select arm-vm-windows, all the pieces that are needed to deploy a virtual machine are added to the Resources section:

  • Storage account
  • Public IP address, which I would remove (and must clean up the dependency in the NIC)
  • Virtual network
  • Virtual NIC
  • Virtual machine

Using Azure Resource Manager JSON snippets in VS Code [Image Credit: Aidan Finn]
Using Azure Resource Manager JSON snippets in VS Code [Image Credit: Aidan Finn]
I’d get all that just by typing “arm” and selecting a menu option!

Enabling ARM JSON snippets is a little fiddly, but not that difficult:

  1. Open the azure-xplat-arm-tooling repository in your browser.
  2. Copy everything from the repository to your clipboard.
  3. Open VS Code.
  4. Click File > Preferences > User Snippets.
  5. Select JSON as the snippet language that you want to configure.
  6. Paste the copied repository before the last brace (one of these: }) in the open json.json file.
  7. Verify that there are no errors – look for highlighted code and check the bar at the bottom left for warnings and alerts.
  8. Save the file and close it.

Where to paste the ARM JSON snippet repository [Image Credit: Aidan Finn]
Where to paste the ARM JSON snippet repository [Image Credit: Aidan Finn]
Now you have all you need to open existing Azure JSON templates, and edit, review and save JSON files to deploy resources in Azure.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.
Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: