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
brew install direnv
For bash:
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
For zsh:
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
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.