Brad Dickinson

Microsoft Azure: Use Visual Studio to Deploy a Virtual Machine

The content below is taken from the original (Microsoft Azure: Use Visual Studio to Deploy a Virtual Machine), to continue reading please visit the site. Remember to respect the Author & Copyright.

In today’s Ask the Admin, I’ll show you how to create an ARM template in Visual Studio for deploying Azure virtual machines (VMs).

As a system administrator, I never thought I’d need to work with Visual Studio (VS) – that scary monolithic piece of software the developers use to conjure up their wares. Tools such as the Windows PowerShell ISE (Integrated Scripting Environment) have, until now, sufficed for my scripting needs. But since Azure has slowly moved away from the classic ‘service management’ model to JSON-based resource manager (ARM) templates, it’s clear that a professional developer tool that understands the JSON syntax, and can help debug and even deploy resources in Azure, is the best way to go.

Not only does VS understand how to parse JSON files, but integration with Azure provides access to Cloud Explorer for resource management and predefined templates so that you can quickly deploy new resources without leaving VS. Having used VS to deploy resources in Azure, this is the way I now recommend you work with Azure templates.

For more information on Azure Resource Manager, see What are Microsoft Azure Resource Groups? and Deploy VMs Using Azure Resource Manager on the Petri IT Knowledgebase.

Install Visual Studio

First you will need to install Visual Studio 15 Community, Professional or Enterprise Edition, with the Azure SDK for .NET. Community Edition is free, so that’s the version I’ll be installing. You can either download and install VS from Microsoft’s website and then add the Azure SDK later, or use Microsoft’s Web Platform Installer (Web PI) to install ‘VS Community Edition with the Azure SDK’ already configured.

VS Community Edition can be downloaded here, and the Web PI here, which can be used to get the Azure SDK for .NET as a separate download, and VS Community Edition with Azure SDK for .NET as an integrated package. When installing VS, make sure you accept the default install options.

Create a New Project in VS

Let’s create a new project in VS and use one of the templates that are provided with the Azure SDK to deploy a VM running Windows Server 2012 R2.

Notice that you should already be logged in to Azure with the Microsoft account that you use to sign in to Windows. The Cloud Explorer pane in VS will show a hierarchical list of resources in your Azure subscription if you have successfully logged in to Azure. If that’s not the case, click on your name in the top right of VS and select Account settings… from the menu to change the login account.

Create a new project in Visual Studio 2015 (Image Credit: Russell Smith)

Deploy a new Azure Resource Group using a template (Image Credit: Russell Smith)

Choose the type of resource to deploy (Image Credit: Russell Smith)

Here you’ll see two files: WindowsVirtualMachine.json and WindowsVirtualMachine.parameters.json. The first file is a template that defines the Azure resource(s) to be created or updated, and the second file contains a list of parameters for the deployment that might change each time a resource is deployed using the template, such as the VM administrator username.

Use JSON Outline to navigate the template (Image Credit: Russell Smith)

The parameters can either be provided in the WindowsVirtualMachine.parameters.json file, or using the new Azure web portal. In this case, the two parameters are set to null, so we’ll edit the file later. Alternatively, these parameter values can be provided at deployment time.

Sponsored

Modify the Template

Now we have a template that looks something like what we need. Let’s delete anything that we don’t want and edit what doesn’t quite fit our requirements.

Add a Resource

You saw how to delete a resource from a template, and it’s just as easy to add resources.

Add a resource to the template (Image Credit: Russell Smith)

You’ll now see DCs appear as a new resource in the resources section of JSON Outline tab. For more information on Availability Sets, see Understanding Azure Availability Sets on Petri.

Add Values to the Parameters File

Before we can deploy the resource, let’s provide values for the adminUsername and dnsNameForPublicIP parameters.

Modify the parameters file (Image Credit: Russell Smith)

Deploy the Solution

The template is now ready, so let’s try and deploy the VM and associated resources. Note that Visual Studio must be launched using an administrator account before you can deploy a solution.

Deploy the solution (Image Credit: Russell Smith)

Deploy the solution (Image Credit: Russell Smith)

The deployment will begin. You may be asked to enter a value for adminPassword even if you entered one in the previous steps. The output window shows the status of the deployment and hopefully the resources will be deployed successfully.

Deploy the solution (Image Credit: Russell Smith)

Check VM Status

Once the solution has been deployed successfully, you can check the status of the VM using Cloud Explorer.

Sponsored

In this article, I’ve shown you how to use an ARM template in Visual Studio to deploy a virtual machine in Microsoft Azure.

The post Microsoft Azure: Use Visual Studio to Deploy a Virtual Machine appeared first on Petri.

Exit mobile version