Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Created October 29, 2016 04:49
Show Gist options
  • Save jamtur01/bcf0f0aefe20e8078898cbd27f121b5b to your computer and use it in GitHub Desktop.
Save jamtur01/bcf0f0aefe20e8078898cbd27f121b5b to your computer and use it in GitHub Desktop.
#!/bin/bash
type terraform >/dev/null 2>&1 || { echo >&2 "I require terraform but it's not installed. Quitting sadly."; exit 1; }
REGION="us-east-1"
BUCKET="remote_state"
ENVIRONMENT=${PWD##*/}
STATE_FILE="terraform.tfstate"
ARGS=$*
remote() {
terraform remote config \
-backend=s3 \
-backend-config="region=${REGION}" \
-backend-config="bucket=${BUCKET}-${ENVIRONMENT}" \
-backend-config="key=${STATE_FILE}"
}
run() {
terraform $ARGS
}
if ! terraform remote pull; then
remote
fi
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment