Last active
August 30, 2017 15:46
-
-
Save jesusvazquez/65ee186511101de92012dd315d099f38 to your computer and use it in GitHub Desktop.
Switch terraform versions
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/sh | |
# Source: https://github.com/jvrplmlmn/osx-config/blob/master/files/zshrc.d/50-terraform-versions.sh | |
function use_terraform { | |
TF_BASE=/opt/terraform | |
if [ -z "$1" ] | |
then | |
echo "Usage: use_terraform X.Y.Z" | |
echo | |
echo "This Terraform versions are available in the system:" | |
ls -1 ${TF_BASE} | |
else | |
TF_VERSION=$1 | |
if [[ ! -a ${TF_BASE}/${TF_VERSION}/terraform ]]; then | |
echo "Terraform ${TF_VERSION} is not installed. Hang tight..." | |
sudo mkdir -p ${TF_BASE}/${TF_VERSION} | |
pushd ${TF_BASE}/${TF_VERSION} | |
sudo wget "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_darwin_amd64.zip" | |
sudo unzip terraform_${TF_VERSION}_darwin_amd64.zip | |
sudo rm -f terraform_${TF_VERSION}_darwin_amd64.zip | |
popd | |
fi | |
sudo ln -sf ${TF_BASE}/${TF_VERSION}/terraform /usr/local/bin/terraform | |
/usr/local/bin/terraform -version | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment