Skip to content

Instantly share code, notes, and snippets.

@cornet
Created July 29, 2019 11:46
Show Gist options
  • Save cornet/67de5682440429db9176fd59ae505ae6 to your computer and use it in GitHub Desktop.
Save cornet/67de5682440429db9176fd59ae505ae6 to your computer and use it in GitHub Desktop.

Direnv Setup

First download the required versions of terraform and terragrunt to the following directory structure:

~/terraform/0.12/terraform   # v0.12.5
~/terraform/0.12/terragrunt  # v0.19
~/terraform/0.11/terraform   # v0.11.8
~/terraform/0.11/terragrunt  # v0.18

Install direnv

brew install direnv

Add shell hooks

For bash:

echo 'eval "$(direnv hook bash)"' >> ~/.bashrc

For zsh:

echo 'eval "$(direnv hook zsh)"'  >> ~/.zshrc

Add functions for switching

Create ~/.direnvrc with the following content:

layout_tf12() {
  PATH_add "${HOME}/terraform/0.12"
}

layout_tf11() {
  PATH_add "${HOME}/terraform/0.11"
} 

Then to auto switch between terraform versions you can create a .envrc file in your project with either

layout_tf12

or

layout_tf11

depending on the version you require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment