Configuring Packer and Terraform with GNU Stow on FreeBSD
Overview
I use hashicorp’s packer and terraform tools to deploy infrastructure. They’re great tools and I’d definitely recommend them over home-rolled solutions or Cloudformation (if you’re in AWS). The problem for me with using these tools was installation. Hashicorp provides prebuilt binaries for most modern OS’s including FreeBSD. This is nice but its pretty tedious to have to download, unzip, and move the binaries around. What I used to do was something along the lines of:
- Download the zip
- Unzip it into my home directory under the
terraform
directory if I was installing terraform. - Then I’d append it to PATH temporarily when I needed to run a
terraform plan
.
This was ok, but it meant always having to remember which terminal sesssion had the tool in its
PATH
.
Recently I ran across an article about managing dot file with
stow. I’d never heard to the stow
utility up to this
point. But its a great utility that symlinks files in its current directory, preserving structure
to the parent directory (default). I figured this would work perfectly with terraforms prebuilt
binaries. Lets dive into how to set up your environment to leverage terraform
and packer
with
stow
.
Configuration
Assuming your already root
. First install stow
and unzip
. Since I’m on FreeBSD
I’ll install them with pkgng:
pkg install -y stow unzip
Grab the latest binaries for packer
and terraform
from hashicorp:
Make a note of the versions you’re downloading since we’ll be using that in our directory structure. As of writting this:
- Packer: 0.10.1
- Terraform: 0.6.16
I want the binaries for terraform
and packer
to be linked in
/usr/local/bin
so lets create the stow directories for these tools:
mkdir -p /usr/local/stow/packer_0.10.1/bin
mkdir -p /usr/local/stow/terraform_0.6.16/bin
Go to the directory where your newly downloaded .zips
are and run:
unzip packer_0.10.1_freebsd_amd64.zip -d /usr/local/stow/packer_0.10.1/bin/
unzip terraform_0.6.16_freebsd_amd64.zip -d /usr/local/stow/terraform_0.6.16/bin/
Now lets use stow:
cd /usr/local/stow
stow packer_0.10.1
stow terraform_0.6.16
As long as you’ve got /usr/local/bin
in your path you’ll be able to use the binaries:
packer --version
terraform --version
Upgrading
When it comes time to upgrade you’ll just need to “unstow” to existing bianries:
cd /usr/local/stow
stow -D packer_0.10.1
stow -D terraform_0.6.16
Then repeat the above configuration
against the new version