Azure CLI for ARM Deployment

I recently had the opportunity to take an Azure class that is typically targeted at preperation for Microsoft's 533 exam. The course was designed by Opsgility, and led by Manesh Raveendran.

While Manesh did a great job presenting the material, which must include PowerShell because that is the command-line environment primarily targeted by Azure, I'm more interested in what I can do with bash and azure-cli.

Here I present one basic scenario, Lab 12, using an Azure Resource Manager (ARM) template to do a deployment from Linux. While this would work from Windows as well, the environment where I ran these commands was Ubuntu 15.04.

Installing the CLI

While one favorite way to learn the CLI is to boot a docker VM, then pull a docker image including the CLI, and then run bash within it, my goal in using Azure CLI is to setup the Continuous Integration server that will do this work. So, we need a basic grasp of deploying the CLI.

  1. Install node using apt:

     sudo apt-get install nodejs nodejs-legacy --upgrade
    
  2. Then, use npm (the Node Package Manager) to install Azure CLI:

     sudo npm install -g azure-cli
    
  3. Make sure that /usr/local/bin is in your path.

Login/Authentication

Since Manesh already has a great post on azure-cli authentication options, we’re going to use the simplest method.

  1. Issue the following command to login:

     azure login
    
  2. Copy and paste the URL printed on the console into your browser.
  3. Enter the 1-time key printed on the console into your browser. This key identifies your computer/IP.
  4. If you have not logged into Azure, you should do that now.
  5. Once the login is complete in your browser, the command-line will finish.
  6. Switch to Azure Resource Manager (ARM) mode:

     azure config mode arm
    

The login is time-limited, but you should still logout

Create a template locally

The Lab instructs you to click the Deploy button on one of the examples in the Azure Quickstart Templates repository. We’re going to edit one of these just a bit, but use one anyway.

  1. Clone the repository using git as follows:

     git clone --depth 100 https://github.com/azure/azure-quickstart-templates templates
    
  2. Change into the appropriate directory

     cd templates/101-vm-simple-linux
    
  3. Modify the template parameters

The parameters file contains special tokens that instruct Azure’s Portal to prompt the user to generate a unique password and domain name. We need to provide these parameters to use the template from Linux (in an automated fashion).

So, use your favorite editor to change the values for the "adminPassword" and the "dnsLabelPrefix" in azuredeploy.parameters.json file. Unlike with the deployment in Azure Portal, the DNS label will not be validated as unique, so validate it as unique, perhaps using dig.

Build a VM using an ARM Template

  1. Create the resource group

     azure group create <groupname>
    
  2. Run the deployment

     azure group deployment create \
       -f azuredeploy.json \
       -e azuredeploy.parameters.json \
       <groupname> <deploymentname>
    

Congratulations!