Skip to content

Instantly share code, notes, and snippets.

@advincze
Last active Jul 1, 2016
Embed
What would you like to do?
#!/bin/bash
#set -e
TERRAFORM_CMD="terraform"
TERRAFORM_VERSION="0.6.16" #"0.7.0-rc2"
if [ -z ${TERRAFORM_BIN_PATH+x} ]; then
TERRAFORM_BIN_PATH="$HOME/.terraform";
fi
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='darwin'
fi
arch="unknown"
unamestr=`uname -m`
if [[ "$unamestr" == 'x86_64' ]]; then
arch='amd64'
elif [[ "$unamestr" == 'i686' ]]; then
arch='386'
fi
if ! type "$TERRAFORM_CMD" > /dev/null 2>&1; then
TERRAFORM_PATH="$TERRAFORM_BIN_PATH/$TERRAFORM_VERSION"
TERRAFORM_CMD="$TERRAFORM_PATH/terraform"
if ! type "$TERRAFORM_CMD" > /dev/null 2>&1; then
mkdir -p "$TERRAFORM_PATH"
curl "https://releases.hashicorp.com/terraform/$TERRAFORM_VERSION/terraform_$TERRAFORM_VERSION"_"$platform"_"$arch".zip | tar -xf- -C $TERRAFORM_PATH/
fi
fi
if [ -a .tfremote ] ;then
$TERRAFORM_CMD get -update
TERRAFORM_REMOTE_CONFIG_OPTS=`awk '{print "-"$1 }' ORS=' ' .tfremote`
TERRAFORM_REMOTE_CONFIG_CMD="$TERRAFORM_CMD remote config $TERRAFORM_REMOTE_CONFIG_OPTS"
eval $TERRAFORM_REMOTE_CONFIG_CMD
fi
rm ./lock.tf > /dev/null 2>&1
$TERRAFORM_CMD $@
cat <<EOF>lock.tf
variable "lock-CAAEB7CC-949A-4AF3-B327-4C60084AAF29" {
description = "this repo needs a remote configuration please use ./terraformw"
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment