Skip to content

Instantly share code, notes, and snippets.

@olen2006
Last active March 23, 2021 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olen2006/9afe9e42cbce30cb399543704410c016 to your computer and use it in GitHub Desktop.
Save olen2006/9afe9e42cbce30cb399543704410c016 to your computer and use it in GitHub Desktop.
script checks and installs latest version of terraforom
#!/bin/bash -xe
CURRENT_VER=$(terraform --version | head -n1 | cut -d " " -f2 | cut -c 2-)
LATEST_RELEASE=$(curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)
if [[ $CURRENT_VER < $LATEST_RELEASE ]];
then
echo "Installing Terraform ${LATEST_RELEASE}..."
rm terraform-*
rm terraform
wget https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/terraform_${LATEST_RELEASE}_linux_amd64.zip
unzip terraform_${LATEST_RELEASE}_linux_amd64.zip
rm terraform_${LATEST_RELEASE}_linux_amd64.zip
mv terraform /usr/local/bin/
echo "Terraforom was updated to the ${LATEST_RELEASE} version"
else
echo "Current version of terraform" $CURRENT_VER "is up to date"
fi
#https://learn.hashicorp.com/tutorials/terraform/install-cli
#https://computingforgeeks.com/how-to-install-terraform-on-ubuntu-centos-7/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment