|
|
@ -0,0 +1,43 @@ |
|
|
|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
TERRAFORM_BIN_PATH="${TERRAFORM_BIN_PATH:-$HOME/.terraform}"; |
|
|
|
TERRAFORM_VERSION=${TERRAFORM_VERSION:-"0.13.5"} |
|
|
|
|
|
|
|
platform='unknown' |
|
|
|
platform_uname=$(uname) |
|
|
|
if [[ "$platform_uname" == 'Linux' ]]; then |
|
|
|
platform='linux' |
|
|
|
elif [[ "$platform_uname" == 'FreeBSD' ]]; then |
|
|
|
platform='freebsd' |
|
|
|
elif [[ "$platform_uname" == 'Darwin' ]]; then |
|
|
|
platform='darwin' |
|
|
|
else |
|
|
|
echo "[$platform_uname] is not recognized as a valid platform" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
arch="unknown" |
|
|
|
arch_uname=$(uname -m) |
|
|
|
if [[ "$arch_uname" == 'x86_64' ]]; then |
|
|
|
arch='amd64' |
|
|
|
elif [[ "$arch_uname" == 'i686' ]]; then |
|
|
|
arch='386' |
|
|
|
else |
|
|
|
echo "[$arch_uname] is not recognized as a valid arch" |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
|
|
|
|
TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${platform}_${arch}".zip |
|
|
|
TERRAFORM_PATH="$TERRAFORM_BIN_PATH/$TERRAFORM_VERSION" |
|
|
|
TERRAFORM_CMD="$TERRAFORM_PATH/terraform" |
|
|
|
if ! type "$TERRAFORM_CMD" > /dev/null 2>&1; then |
|
|
|
if [ ! -f "$TERRAFORM_PATH.zip" ]; then |
|
|
|
echo "Downloading $TERRAFORM_URL" |
|
|
|
mkdir -p "$TERRAFORM_PATH" |
|
|
|
curl -ls "$TERRAFORM_URL" -o "$TERRAFORM_PATH.zip" |
|
|
|
fi |
|
|
|
cd "$TERRAFORM_PATH" && unzip "$TERRAFORM_PATH.zip" && cd - || exit 2 |
|
|
|
fi |
|
|
|
|
|
|
|
# shellcheck disable=SC2068 |
|
|
|
$TERRAFORM_CMD $@ |