~damien/infrastructure

d65c8cfbeb1ed813c19025488e588067f327192b — Damien Radtke 4 months ago c79403c
Set cluster env even in non-interactive commands
2 files changed, 10 insertions(+), 5 deletions(-)

M support/.bashrc
M tools/set-cluster-env
M support/.bashrc => support/.bashrc +2 -2
@@ 1,3 1,5 @@
source "$(which set-cluster-env)" "${HOME}/infrastructure/terraform/"

# If stdout is connected to a terminal, return early. Without this, git hooks
# and other non-interactive commands over SSH can fail.
[[ ! -t 1 ]] && return


@@ 5,8 7,6 @@
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
export PATH="${PATH}:${HOME}/go/bin"

source "$(which set-cluster-env)" "${HOME}/infrastructure/terraform/"

complete -C /usr/local/bin/vault vault
complete -C /usr/local/bin/nomad nomad
complete -C /usr/local/bin/consul consul

M tools/set-cluster-env => tools/set-cluster-env +8 -3
@@ 9,15 9,20 @@
#     $ source "$(which set-cluster-env)" "${HOME}/infrastructure/terraform/"
#

# If non-interactive, set TERM To dumb to prevent fancy output or errors.
if [[ ! -t 1 ]]; then
	export TERM=dumb
fi

if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
	echo "$(tput setaf 1)set-cluster-env should be sourced, not executed$(tput sgr0)"
	echo "$(tput setaf 1)set-cluster-env should be sourced, not executed$(tput sgr0)" >&2
	exit 1
fi

state_dir="${1:-.}"

if [[ ! -d "${state_dir}" ]]; then
	echo "directory '${state_dir}' not found"
	echo "directory '${state_dir}' not found" >&2

	# This puts everything else into an else case here rather than exiting
	# because it is intended to be sourced, and running "exit" in your


@@ 44,7 49,7 @@ else
	export VAULT_CLIENT_CERT="${HOME}/vault-cli.pem"
	export VAULT_CLIENT_KEY="${HOME}/vault-cli-key.pem"

	echo "$(tput dim)cluster environment set for workspace \"$(terraform workspace show)\"$(tput sgr0)"
	echo "$(tput dim)cluster environment set for workspace \"$(terraform workspace show)\"$(tput sgr0)" >&2

	popd >/dev/null
fi