Learn the many ways you can make your Microsoft Azure work easier by integrating with Visual Studio Code (VS Code), Microsoft's free, open-source, cross-platform code editor.
Latest posts by Timothy Warner (see all)

I hope by now you've moved from the Windows PowerShell Integrated Scripting Environment (PowerShell ISE) to Visual Studio Code for your administrative automation. Accordingly, your business might rely on the Microsoft Azure cloud a lot more than it has in years past.

If you've thought to yourself, "I wonder how VS Code integrates with Microsoft Azure?" then this tutorial is for you. By the end of this lesson, you'll be familiar with the major touchpoints between VS Code and Azure that can help you out regardless of whether your work is more operations- or development-focused. Let's begin!

Build your Azure development environment

Besides Visual Studio Code itself, the following are the baseline dependencies that I think you should have installed on your workstation to facilitate your work in Azure:

If you use the Chocolatey package manager, like I do, you can install all of the above (with the exception of the Azure Developer CLI) by running a single command:

choco install -y git vscode azure-cli az.powershell bicep

Until Microsoft uploads the Azure Developer CLI to the Chocolatey community package repository, you can run the following PowerShell command to install it:

powershell -ex AllSigned -c "Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression"

You might already know that your flexibility with Visual Studio Code is dramatically improved by the use of extensions. Specifically, I'd like to introduce you to some key Microsoft Azure extensions that represent the "secret sauce" to VS Code-based Azure productivity.

Azure account management

The Azure Account extension should be the first VS Code extension you install. The reason is simple: you should be able to use VS Code for your Azure work without having to reauthenticate to your Azure subscription again and again and again.

Follow these steps if you haven't installed a VS Code extension yet:

  1. Open VS Code, and click the Extensions button in the Activity Bar.
  2. In the Search Extensions in Marketplace text box, search for the string @ext:azure. You could search only for azure; the @ext: prefix simply filters for only extensions and leaves behind stuff like color themes, icon packs, snippets, and the like.
  3. Select the Azure Account extension, and click Install. Some VS Code extensions require you to reload the application prior to their first use.

You can easily get to a particular extension's options by loading up the extension's Marketplace page, opening the gear menu, and selecting Extension settings, as shown in the following screenshot.

Install a Visual Studio Code extension

Install a Visual Studio Code extension

Visual Studio Code relies on keyboard shortcuts and the text-based Command Palette for most navigation and administration tasks. To get signed into Azure, click View > Command Palette, and type Azure:Sign in.

You'll find that every extension includes a command library, with each command prefixed by a fixed value. For the Azure account extension, that prefix is, simply enough, Azure.

Use the Visual Studio Code Command Palette

Use the Visual Studio Code Command Palette

Once you complete the browser-based authentication flow, you can use the Azure: Select subscriptions command from the Command Palette to ensure you're connected to the correct subscription.

As the following screenshot demonstrates, the VS Code status bar reminds you of which Azure subscription you're currently attached to.

Verify your Azure subscription context

Verify your Azure subscription context

Azure infrastructure as code

Like other public cloud platforms, Microsoft Azure uses declarative, idempotent JavaScript Object Notation (JSON) templates as its default deployment vehicle. To give you the best Azure Resource Manager (ARM) deployment template support, revisit the Extensions Marketplace, and install the following VS Code extensions:

After you've done so, you now have full language support for both ARM JSON and the Bicep domain-specific language (DSL). You also get full template validation against the ARM deployment schemas.

Now create two new files, one with the .json extension and the other with the .bicep extension. Because you have the language extensions loaded, VS Code should report the correct file types on the status bar.

If, for whatever reason, VS Code auto-detects the file type association incorrectly, fix it by clicking the Select Language Mode status bar button and making the appropriate correction. I'll show you this in the next screenshot.

Set the language mode in VS Code

Set the language mode in VS Code

Of course, now that you have Azure PowerShell, the Azure CLI, and the Bicep CLI installed, you can deploy your Azure templates directly from the VS Code terminal. Here's an example of deploying a Bicep template using Azure PowerShell:

New-AzResourceGroupDeployment -Name 'bicep-deploy' -ResourceGroupName '4sysops' -TemplateFile './main.bicep'

If you're a Terraform shop, don't worry—Visual Studio Code has you covered. Install Terraform and then load up one of the VS Code language extensions:

What's the difference between these two extensions? My understanding is that the Microsoft one is essentially a wrapper over the Terraform CLI. Personally, I'm comfortable enough with the Terraform CLI and HashiCorp Configuration Language (HCL) that I use only HashiCorp's own extension to give me stuff like IntelliSense code completion and configuration validation. You know the saying: "Your mileage may vary."

Work with other Azure services

Thus far, our VS Code-based Azure work has shown the following high-level workflow:

  1. Install the appropriate binary dependencies and VS Code extensions.
  2. Configure the extension to suit your preferences.
  3. Ensure file types are associated with the correct extensions.

Let me wrap up this tutorial with a list of VS Code extensions to suit additional Microsoft Azure-based work situations:

The Microsoft Azure Resources VS Code extension in action

The Microsoft Azure Resources VS Code extension in action

What's especially cool about the Microsoft Azure Resources extension is that VS Code will prompt you to install the appropriate extensions if you're missing one as you browse your Azure inventory.

Subscribe to 4sysops newsletter!

Well, that's it! I hope I gave you a head start in getting productive with your Azure cloud work in Visual Studio Code.

avatar
2 Comments
  1. I’ve been thinking of installing VS code on my machine to move away from ISE as I am slowly progressing in my DevOps journey. You saved me from a ton of research, thank you for this awesome post.

    • Author
      Tim Warner 1 month ago

      You’re welcome, Surender! I’m glad you liked the post. -Tim

Leave a reply

Please enclose code in pre tags

Your email address will not be published.

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account