Skip to content

Instantly share code, notes, and snippets.

@gordonbondon
Created January 5, 2020 15:26
Show Gist options
  • Save gordonbondon/cce9462a5459740fbc38d86c4fc742fa to your computer and use it in GitHub Desktop.
Save gordonbondon/cce9462a5459740fbc38d86c4fc742fa to your computer and use it in GitHub Desktop.
Bash scripts for atlantis custom steps
#!/usr/bin/env bash
set -e
# dont add pipefail because we need to catch exit code inside pipe
MISSING_VAR_MESSAGE='must be running inside atlantis'
: "${ATLANTIS_TERRAFORM_VERSION:?$MISSING_VAR_MESSAGE}"
: "${DIR:?$MISSING_VAR_MESSAGE}"
: "${PLANFILE:?$MISSING_VAR_MESSAGE}"
DIR_REPLACED=${DIR//\//_}
export PATH="${ATLANTIS_DATA_DIR}/bin:$PATH"
export TFMASK_VALUES_REGEX="(?i)^.*(secret|password|token).*$"
export TF_BINARY="terraform${ATLANTIS_TERRAFORM_VERSION}"
export TF_LOG_FILE="/logs/${PULL_NUM}__${DIR_REPLACED}.log"
function clean_log() {
rm -rf "${TF_LOG_FILE}"
}
trap clean_log EXIT
# change to project directory
cd "${DIR}" || exit 1
"${TF_BINARY}" apply -no-color "${PLANFILE}" | tfmask |& tee "${TF_LOG_FILE}" || true
# exit with proper exit code of terraform
exit "${PIPESTATUS[0]}"
#!/usr/bin/env bash
set -e
# dont add pipefail because we need to catch exit code inside pipe
MISSING_VAR_MESSAGE='must be running inside atlantis'
: "${ATLANTIS_TERRAFORM_VERSION:?$MISSING_VAR_MESSAGE}"
: "${DIR:?$MISSING_VAR_MESSAGE}"
: "${PLANFILE:?$MISSING_VAR_MESSAGE}"
DIR_REPLACED=${DIR//\//_}
export PATH="${ATLANTIS_DATA_DIR}/bin:$PATH"
export TFMASK_VALUES_REGEX="(?i)^.*(secret|password|token).*$"
export TF_BINARY="terraform${ATLANTIS_TERRAFORM_VERSION}"
export TF_LOG_FILE="/logs/${PULL_NUM}__${DIR_REPLACED}.log"
function clean_log() {
rm -rf "${TF_LOG_FILE}"
}
trap clean_log EXIT
# skip scenery on > 0.12
scenery="scenery"
tf_attr=""
if [[ ${ATLANTIS_TERRAFORM_VERSION} == *"0.12"* ]]; then
scenery="tee"
tf_attr="-no-color"
fi
# change to project directory
cd "${DIR}" || exit 1
"${TF_BINARY}" plan ${tf_attr} -out "${PLANFILE}" | "${scenery}" | tfmask |& tee "${TF_LOG_FILE}" || true
# exit with proper exit code of terraform
exit "${PIPESTATUS[0]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment