Hashicorp Terraform Logo

OpenStack infrastructure automation with Terraform – Part 1

Update: The Openstack provider has been merged into terraform. It comes with the terraform default download as of 0.4.0.

Get it HERE: https://terraform.io/downloads.html

Then proceed directly to the second part of this series to get up and running with Terraform on Openstack quickly!

Or.. read more below for the original post.

TL;DR: Two post series for automating the configuration and VM deployment of a brand new tenant / project in OpenStack with Terraform, using the new Terraform OpenStack Provider.

With the OpenStack provider for Terraform nearly accepted into the Terraform release, I thought it was time to demonstrate the power of this currently beta provider.

In this blog post we will:

  • Compile the openstack terraform provider from the github pull request.

In the followup post, we will:

  • Write a terraform ‘.TF’ file to describe our desired deployment state including;
    • Neutron networks/subnets
    • Neutron gateways
    • Keypairs and Security Groups
    • Virtual machines and Volumes
    • Virtual IP’s
    • Load balancers (LBaaS).
  • Have terraform deploy, modify and rip down our infrastructure.

1. Compile the Terraform Openstack Provider

Terraform is written in Golang, all terraform plugins are standalone golang binaries that terraform will check for in it’s local dir and gopath.

As Openstack support isn’t yet shipped with terraform, lets compile the provider based on the open github pull request.

https://github.com/hashicorp/terraform/pull/924

Clone the Terraform Github repo:

Modify the git config so we can see PR’s locally: 

 We can now create local branches which track Pull Requests
thanks to https://gist.github.com/piscisaureus/3342247 for this tip!

 Check Dependancies! 

I am assuming you have a working golang environment installed on your system this point; The topic has been covered many times in far nicer ways than I could cover here. For example: http://skife.org/golang/2013/03/24/go_dev_env.html

I’m also assuming you have downloaded the terraform binary for your system from HERE and it’s in your $PATH  so that you can run terraform as follows.

Compile Terraform Openstack plugin!

We move the terraform git repo we cloned into our  $GOPATH/src directory, check we have the required dependancies to compile a terraform plugin, then compile the plugin.

Finally we place the resulting plugin into our $PATH along with the binary installation of Terraform we already have installed.

Notice, once built, we rename the binary to ‘terraform-provider-openstack’. This is due to Terraform plugin naming convention. Allowing terraform to discover plugins in it’s directory/path.

You will see this if you look at your Terraform install location with the existing bundled providers:

Add the new provider to your  $PATH location:

Finally, check the binary is correct and Terraform accepts the provider.

Terraform would error on this simple manifest if it could not find a provider named ‘openstack’:

That’s It! Terraform is ready to rock your Openstack deployment!

In the next blog post, we’ll take it for a spin and automate some infrastructure.

 

 

 

Leave a Reply