Michael in Automation 10 minutes

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 for me 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:
 name: azurerm

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

 name: chef_zero

 name: inspec

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

 - name: default
 - recipe[contributors::default]

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

command description
kitchen create creates azure infrastructure for running, powers on machines
kitchen converge does kitchen create if needed, will converge the node using chef
kitchen verify does create and converge if needed, runs the tests that you've written
kitchen test does everything: create, converge, verify
kitchen destroy don't forget this one; it removes the resources

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