With Hashicorp´s terraform it becomes really easy to provision virtual machines, templates on different providers (AWS, azure, Google, Kubernetes, etc.). When you now deploy your machines you need to configure, patch and manage them afterwards. This is were Chef has strengths. So teaming up terraform with Chef as so called provisioner makes perfect sense. In this post I just want to show how easy this is.

In my example I will deploy a Windows 2012 R2 machine on AWS and install putty, create some folders and check for registry keys on the newly created server. First you need to write a plan (example.tf):

Pro-Tip: Please use the “file” option in the “user_key” variable as it will fail if you just set the direct path. You can also add recreate_client = true in the provisioner section if you play around and create the same machine more than once.

As you can see I already set the initial run_list and Chef-Server in this plan, so if everything works perfect it should create a Windows 2012R2 machine, install and configure the Chef-Client to use the public available Chef-Server and finally run my cookbook. You can kick off the creation using “terraform apply”:


Pro-Tip: You can see the Chef-Client run in the logs, if anything fails you will see it. That means you can use terraform as staging or testing environment as well.

Because we defined an output in the plan you can see the public IP address of the newly created machine as a result. When we now connect to the system using RDP there should be a putty available and several folders on the desktop:

This example shows how easy it is to use a terraform definition to kick of a full deployment and configuration with just one CLI command. Please note that you can easily change your target cloud infrastructure to vSphere or azure now by changing this terraform file and it´s provider.