Over the last year, I’ve primarily used Hyper-V as my driver for Kitchen in developing Chef cookbooks for Windows. I’m now starting to branch out to build some cookbooks for Linux and really don’t want to build my own Hyper-V images. So Vagrant is the obvious choice but I still use Hyper-V and don’t want to swap between VirtualBox and Hyper-V constantly. Enabling Hyper-V disables other virtualization options like VirtualBox or VMWare on the same box.
Thankfully Vagrant also supports/provides a Hyper-V provider.
https://www.vagrantup.com/docs/hyperv/
Vagrant is the default driver for Kitchen and uses VirtualBox for virtualization by default. Kitchen can be configured to use Hyper-V with Vagrant but it isn’t documented very well. Enter the community! Michael T Lombardi, a PowerShell community member and Puppet employee, worked out the proper Kitchen configuration with the help of Matt Wrock in the following kitchen-vagrant issue:
https://github.com/test-kitchen/kitchen-vagrant/issues/297
Here is the final Kitchen.yml they ended up with:
driver: name: vagrant provisioner: name: chef_zero always_update_cookbooks: true verifier: name: inspec transport: name: winrm elevated: true
platforms: - name: Windows2012R2 driver: box: mwrock/Windows2012R2 provider: hyperv memory: 2048 cpus: 2 vm_hostname: chef-fu network: - ["private_network", {bridge: "Guest"}]
suites: - name: default run_list: - recipe[learn_chef_iis::default] verifier: inspec_tests: - test/recipes attributes:
Now we can use the vast registry of Vagrant boxes with Kitchen without sacrificing Hyper-V in the process. I will be using Vagrant with Hyper-V going forward for all my Chef cookbook testing.
Few Additional Tips
Make sure you are using the latest kitchen-vagrant gem (currently version 1.2.1). My memory and cpu configuration wasn’t being applied in Hyper-V until I upgraded this gem.
You can only use Vagrant boxes that support the Hyper-V provider. You can easily filter your search to select providers on the Hashicorp Discover Vagrant Boxes page:
Join me in thanking Michael and Matt for their work on the Github issue so they know they are appreciated and will continue investing in the community.
Happy Testing!