Manage Azure VMs with VSCode

Visual Studio Code is not only a powerful and lightweight IDE for coding but also the new way of managing various resources on many platforms, including Azure and Azure DevOps. It is simple to add extensions to use new languages, customize themes, and connect to external services. In this post, we will be looking at how to create and manage an Azure VM using VSCode.
Latest posts by Baki Onur Okutucu (see all)

Installation ^

Before installing the Azure Virtual Machines extension, we need to ensure that the Azure Account extension has been installed. This provides us with a single sign-in experience for all Azure extensions, including Azure Virtual Machines.

Azure account allows a central sign in experience

Azure account allows a central sign in experience

Now we can install the Azure Virtual Machines extension as well. You can simply search, find, and install it as shown below.

Azure Virtual Machines is just one of the Azure extensions available for VSCode

Azure Virtual Machines is just one of the Azure extensions available for VSCode

Once installed, an Azure icon will appear in the activity bar. This icon represents all Azure-related extensions, where you can manage a wide range of services. So when you install other Azure extensions, such as Azure Storage or Azure Functions, they also appear under this section. We can now see that Virtual Machines is added as a new service in VSCode.

All VMs across subscriptions

All VMs across subscriptions

It lists all VMs across all subscriptions over which you have permissions. Because the Azure Account extension is already installed, we no longer need to be authenticated for the Azure Virtual Machines extension to list VMs.

Create a new VM ^

To create a new VM, we can simply click on the plus sign (+) and follow the instructions in VSCode. It will then ask a set of questions to create the VM with the specified details.

Creating a new VM in VSCode

We need to specify the following to create the VM:

  • The subscription in which the VM will be created.
  • Name of the VM
  • The passphrase that we will be using to connect to the VM via SSH
  • The location where the VM will be created
Creating a new VM in VSCode

Creating a new VM in VSCode

After these simple steps, VSCode will start creating the VM with the info that we provided.

A new VM is being provisioned

A new VM is being provisioned

During the creation, we can check the logs to get a better view of what is being created. To check the logs, we need to select Azure Virtual Machines from the dropdown box in the upper right corner and then get to the "Output" section.

Output of the created resources as part of VM deployment

Output of the created resources as part of VM deployment

Once the provisioning is done, we can see the newly created VM under the subscription. We now have two options to manage this VM. We can either right-click it and select "Open in Portal" or manage it via SSH.

Open in Portal option in the context menu on a VM

Open in Portal option in the context menu on a VM

Connecting to VM in VSCode using Remote - SSH ^

I'd like to continue with the SSH option. So I need to install another extension, Remote - SSH. This will enable us to connect to our VM via SSH.

Remote SSH is another useful extension to connect to VMs via SSH

Remote SSH is another useful extension to connect to VMs via SSH

Once the Remote - SSH extension is installed, all we need to do is add our Linux VM as a new target. Here, I need to enter the following SSH command, which allows me to connect to an Azure VM using a default username, "azureuser," and the DNS name of the VM.

Adding a new VM as an SSH target

Adding a new VM as an SSH target

The second step is the location of the SSH config file, where VSCode stores the details of the targets.

Selecting the SSH configuration file

Selecting the SSH configuration file

Once the target is added, we can right-click it and connect to it.

Connecting to the VM via SSH

Connecting to the VM via SSH

The last step is where we provide the passphrase that we created earlier, during provisioning.

Entering the passphrase to connect to the VM

Entering the passphrase to connect to the VM

Finally, the green checkmark appears on the target, which means that the VM has been connected and is ready to be used. The rest is just to manage the VM the way you like. In my scenario, I wanted to install PowerShell 7.

The VM is ready to be managed via SSH in VSCode

The VM is ready to be managed via SSH in VSCode

Conclusion ^

VSCode is growing more popular every day. Supporting a wide range of programming languages and services, its lightweight design and built-in integrations such as Git makes life much easier for both developers and system administrators. The Azure Virtual Machines extension in VSCode is yet another great service integration that allows us to deploy VMs on Azure with a few clicks.

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

0
Share
0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

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