Tutorial for Test Kitchen with Azure
By Michael Hedgpeth · March 4, 2016
Tutorial for Test Kitchen with Azure

As I wrote in the last post, Test Kitchen as one of the things that attracted me to Chef. There was a problem, though: running Windows on virtual machines automatically is difficult.

I’ve spent quite a bit of time trying to create a vagrant image using Matt Wrock’s excellent blog as a resource, and haven’t quite gotten it there yet. Plus, if I go the vagrant route, people have to have powerful machines on which to run test kitchen. The more I worked through that option, the more I because discouraged and dismayed that this may just never work for us.

And then I discovered azure.

Don’t get me wrong: I’m not a Microsoft fanboy. But there are some great advantages to going this route:

  1. Through my Microsoft-friendly workplace I get a MSDN Subscription, with which I get $50/month credit to use azure. So this is free, and I can run test kitchen on not-my compute resources.
  2. Microsoft by definition is going to get Windows images right. So I don’t have to fight it anymore. I can just use it. It just works, just like it should.
  3. Stuart Preston wrote a plugin that gets anyone past the learning curve very quickly. With this plugin you don’t have to really know anything about azure to use it for test kitchen

These reasons are so compelling, this is what our teams will be going with in the coming months. It’s critical that everyone be able to run test kitchen easily, and azure gives us the best shot at doing that without a lot of drama.

Setting up was easy:

  1. Activate your subscription from your MSDN account
  2. Install the Azure CLI for Windows
  3. Follow the directions on the kitchen-azurerm main page to set up a Security Principal, Tenant, Password, and configure it in your user directory
  4. In a simple cookbook, create a simple kitchen.yml file like this:
---
driver:
  name: azurerm

driver_config:
  subscription_id: <%= ENV['AZURE_SUBSCRIPTION_ID'] %>
  location: 'South Central US'
  machine_size: 'Standard_D1'

provisioner:
  name: chef_zero

verifier:
  name: inspec

platforms:
  - name: windows2012-r2
    driver_config:
    image_urn: MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:latest
    transport:
      name: winrm
  - name: centos71
    driver_config:
    image_urn: OpenLogic:CentOS:7.1:latest

suites:
  - name: default
    run_list:
      - recipe[contributors::default]
    attributes:

It’s really that simple. Now I can run test kitchen commands:

commanddescription
kitchen createcreates azure infrastructure for running, powers on machines
kitchen convergedoes kitchen create if needed, will converge the node using Chef
kitchen verifydoes create and converge if needed, runs the tests that you’ve written
kitchen testdoes everything: create, converge, verify
kitchen destroydon’t forget this one; it removes the resources

There you have it, go through those easy steps, and you have Kitchen working with Azure.