Building the development version of Terraform

3 Dec 2014

Instructions on how to build the development version of Terraform.

First you need to install Go, I have a script for this that would be easy to adapt for your needs. It installs Go, but also downloads some common projects (go-bindata, lint) and my own projects (gosnmp, evaler).

#!/bin/bash

## install go

tgz=go1.3.3.linux-amd64.tar.gz
url=https://storage.googleapis.com/golang/$tgz

if ! [ -f /var/tmp/$tgz ] ; then
	cd /var/tmp
	wget $url
fi

if ! [ -d /usr/local/go ] ; then
	sudo tar -C /usr/local -xzf /var/tmp/$tgz
fi

## setup dev directory structure

mkdir -p ~/go/{sonia,thirdparty}/{bin,pkg,src}

cd ~/go/thirdparty/src
#---------------------

read -p "Install third party repos? (go-bindata, lint)"
if [[ $REPLY =~ ^[Yy]$ ]] ; then
	if ! [ -d github.com/jteeuwen/go-bindata ] ; then
		go get github.com/jteeuwen/go-bindata/...
		cp ~/go/thirdparty/bin/go-bindata ~/bin
	fi

	if ! [ -d github.com/golang/lint ] ; then
		go get github.com/golang/lint/golint
		cp ~/go/thirdparty/bin/golint ~/bin
	fi
fi

cd ~/go/sonia/src
#----------------

read -p "Install soniah repos? (gosnmp, evaler)"
if [[ $REPLY =~ ^[Yy]$ ]] ; then
	# do 'git clone' not 'go get' so origin is writeable
	dir=github.com/soniah
	if ! [ -d $dir/evaler ] ; then
		mkdir -p $dir
		cd $dir
		git clone git@github.com:soniah/evaler.git
		cd -
	fi

	dir=github.com/soniah
	if ! [ -d $dir/gosnmp ] ; then
		mkdir -p $dir
		cd $dir
		git clone git@github.com:soniah/gosnmp.git
		cd -
	fi
fi

A common pattern in Go (which my setup script demonstrates) is to split your code from thirdparty code. This requires configuring your shell (~/.zshrc, ~/.bashrc):

export GOPATH=~/go/thirdparty:~/go/sonia
export PATH=${GOPATH//://bin:}/bin:$PATH

Then you need to follow the Terraform instructions for building, that is:

$ cd ~/go/thirdparty/src
$ go get -u github.com/mitchellh/gox
$ cd ~/go/thirdparty/src/github.com/hashicorp/terraform
$ make updatedeps
$ make dev
# put the binaries somewhere in your path, eg /usr/local/bin
$ sudo cp bin/terraform* /usr/local/bin
comments powered by Disqus

  « Previous: Next: »