Skip to content

Instantly share code, notes, and snippets.

@kitos9112
Last active March 26, 2024 14:41
Show Gist options
  • Save kitos9112/67c1ab959680492197e9bfe973297f2f to your computer and use it in GitHub Desktop.
Save kitos9112/67c1ab959680492197e9bfe973297f2f to your computer and use it in GitHub Desktop.
Bash script that automatically updates to latest version of Terragrunt
#!/bin/bash
###########################################################################
# Fetch and install the latest Terragrunt version
# curl -Ls https://gist.githubusercontent.com/kitos9112/67c1ab959680492197e9bfe973297f2f/raw/2331cb5fb08d3c307a6ae8e84fc4685314151571/get-terragrunt.sh| bash
##########################################################################
set -e
set -x
function get_latest_github_release {
curl -s https://api.github.com/repos/$1/$2/releases/latest | grep -oP '"tag_name": "[v]\K(.*)(?=")'
}
INSTALL_DIR='/usr/local/bin'
REGEX="^PATH=.*\K$INSTALL_DIR(?=.*)"
if [[ $(env | grep -oP $REGEX) != $INSTALL_DIR ]]; then
echo "Looks like your install directory $INSTALL_DIR is not in your PATH. Make sure you export it"; fi
INSTALLED_TERRAGRUNT_VERSION=$(terragrunt --version | grep -Poie '\d+.\d+.\d+')
LATEST_TERRAGRUNT_RELEASE=$(get_latest_github_release gruntwork-io terragrunt)
# Download and install Terragrunt if there is a version mismatch
if [[ ${LATEST_TERRAGRUNT_RELEASE} != ${INSTALLED_TERRAGRUNT_VERSION} ]]; then
echo "Installing Terragrunt ${LATEST_RELEASE}..."
wget https://github.com/gruntwork-io/terragrunt/releases/download/v${LATEST_TERRAGRUNT_RELEASE}/terragrunt_linux_amd64
mv terragrunt_linux_amd64 terragrunt
sudo install terragrunt ${INSTALL_DIR}/terragrunt
rm -rf terragrunt
else
echo "Nothing done. Latest Terragrunt already installed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment