Last active
August 4, 2020 09:50
-
-
Save johnl/b87d53ef738fb76b79298a3435bdf6fb to your computer and use it in GitHub Desktop.
a script to run the right version of terraform for the current repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this script expects to find each terraform version binary available in the path | |
# with the filename format terraform_0.x.x | |
# | |
# requires jq | |
# doesn't currently support reading states in terraform workspaces | |
function die { | |
echo $1 | |
exit 1 | |
} | |
if test -e .terraform_version ; then | |
tfver=$(cat .terraform_version | grep -Eo '[0-9.]+') | |
else | |
test -e terraform.tfstate || die "no terraform.tfstate file found, can't find version" | |
tfver=$(jq -r .terraform_version terraform.tfstate | grep -Eo '[0-9.]+') | |
fi | |
exec terraform_$tfver $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment