CD of an Azure virtual machine using a Resource Manager template

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.

Prerequisites

Before you begin, you need a CI build that creates your Azure RM template. To set up CI, see:

Define and test your CD release process

Carry out the following steps to deploy the Azure Resource Group.

  1. Open the Releases tab of the Build & Release hub and choose the "+" icon to create a new release definition.

  2. In the Create release definition dialog, select the Empty template and choose Next.

  3. In the next page, select the build definition you created earlier and choose Create. This creates a new release definition with one default environment.

  4. In the new release definition, select + Add tasks and add an Azure Resource Group Deployment task. Optionally edit the name to help identify the task, such as Provision Windows 2012 R2 VM.

  5. Configure the Azure Resource Group Deployment task as follows:

    Azure Resource Group Deployment Deploy: Azure Resource Group Deployment - Deploy files to an Azure Resource Group.

    • Azure Subscription: Select a connection from the list under Available Azure Service Connections or create a more restricted permissions connection to your Azure subscription. For more details, see Azure Resource Manager service endpoint.

    • Action: Create or Update Resource Group

    • Resource Group: The name for a new resource group, or an existing resource group name.

    • Template location: The path of the Resource Manager template; for example:
      $(System.DefaultWorkingDirectory)\ASPNet4.CI\drop\HelloWorldARM\Templates\WindowsVirtualMachine.json

    • Template Parameters: The path of the Resource Manager template parameters file; for example:
      $(System.DefaultWorkingDirectory)\ASPNet4.CI\drop\HelloWorldARM\Templates\WindowsVirtualMachine.parameters.json

    • Override Template Parameters: A list of values for the parameters in the template; for example:
      -adminUsername $(vmuser) -adminPassword (ConvertTo-SecureString -String $(vmpassword) -AsPlainText -Force) -dnsNameForPublicIP $(dns)'
      Use the ... button to open the parameters editor dialog.

    • Enable Deployment Prerequisites: Checked.

    • Output - Resource Group: The name of the Resource Group output from the task as a value that can be used as an input to further deployment tasks.

    Checking the Enable Deployment Prerequisites checkbox configures WinRM on the virtual machine and enables execution of remote PowerShell scripts, which may be required to deploy an application. Also notice the use of ConvertTo-SecureString to specify the value for adminPassword. You must do this because adminPassword is defined as a SecureString type in the Resource Manager template file.

  6. If you used variables in the parameters of the Azure Resource Group Deployment task, such as vmuser, vmpassword, and dns, set the values for them in the environment configuration variables. Encrypt the value of vmpassword by selecting the "padlock" icon.

  7. Enter a name for the release definition and save it.

  8. Create a new release, select the latest build, and deploy it to the single environment.