Build an Azure virtual machine using an Azure RM template

Last Update: 4/7/2017

Team Services | TFS 2017 | TFS 2015 | Previous versions

In just a few steps, you can provision Azure virtual machines (VMs) using Resource Manager (RM) templates. Managing the definitions for virtual machines in this way is considered Infrastructure as code and is a good DevOps practice.

For this example, the template for creating the Azure VMs must be checked into a version control repository along with the rest of the application code, and it must be published as part of the build output.

Get set up

Before you can build the solution, you must create an Azure RM template.

Create the template

Follow these steps to create and check-in a new Resource Manager template.

  1. In Visual Studio, choose File | Add | New project and add a new Azure Resource Group project to your solution.

  2. When prompted for an Azure template, select Windows Virtual Machine.

    The Windows Virtual Machine template is a simple example of provisioning a single virtual machine in Azure. For provisioning other types of resources, you can either edit the WindowsVirtualMachine.json file, select other templates in the project creation wizard, or download one of the many templates available at https://github.com/Azure/azure-quickstart-templates.

  3. Add a project for your app to the solution. This could be a project for an existing app, or a new project created from the Visual Studio File | Add | New project menu.

  4. Save the entire solution (not just the project) and commit the changes into a Team Foundation Server or Visual Studio Team Services Git repository.

Create the build definition

Carry out the following steps to publish an artifact with the Resource Manager template files.

  1. Make sure that the template files from the HelloWorldARM project are included in the artifacts published by Build.

  2. Queue a new build and verify that the artifact contains the Templates folder containing the template files WindowsVirtualMachine.json and WindowsVirtualMachine.parameters.json.

Enable continuous integration (CI)

On the Triggers tab, enable continuous integration (CI). This tells the system to queue a build whenever someone on your team commits or checks in new code.

Queue and test the build

Save the build definition and queue a new build by selecting the Queue new build command. Once the build is done, click Artifacts and then Explore to see the template files produced by the build. This is the template that your release definition will consume to provision an Azure virtual machine.

Deploy your virtual machine

After you've run the build, you're ready to create a release definition to deploy your virtual machine:

Q&A

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.

Help and support