Skip to content

Instantly share code, notes, and snippets.

@danisla
Last active November 9, 2017 08:42
Show Gist options
  • Save danisla/537b84ff902aea3a98dd4f7a010d56e4 to your computer and use it in GitHub Desktop.
Save danisla/537b84ff902aea3a98dd4f7a010d56e4 to your computer and use it in GitHub Desktop.
Terraform with Docker for Linux, OSX and Google Cloud Shell
function terraform()
{
if [[ -e ${HOME}/.config/gcloud/credentials.json ]]; then
GOOGLE_CREDENTIALS="$(cat ${HOME}/.config/gcloud/credentials.json | tr '\n' ' ')";
fi;
GOOGLE_PROJECT=${DEVSHELL_PROJECT_ID:-$(gcloud config get-value project 2>/dev/null)};
VERSION=latest
docker run -u "${UID}:${UID}" -it --rm -v ${HOME}:${HOME} --env-file <(env|awk '/^.+=/'|grep -v TMPDIR) -e GOOGLE_CREDENTIALS="${GOOGLE_CREDENTIALS}" -e GOOGLE_PROJECT="${GOOGLE_PROJECT}" -w $PWD hashicorp/terraform:${VERSION} $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment