Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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