Skip to content

Commit bff4553

Browse files
committed
Fix #374: Route tfenv log output to stderr in terraform shim context
When tfenv auto-installs via the terraform shim (bin/terraform), info and warn messages were sent to stdout, mixing with terraform output. This broke piped commands like: terraform version -json | jq Set TFENV_SHIM_MODE=1 in bin/terraform so bashlog routes info/warn to stderr in that context. Direct tfenv commands (tfenv install, etc.) are unaffected — their info output remains on stdout.
1 parent a3c943e commit bff4553

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

bin/terraform

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ done;
5858
# Begin Script Body #
5959
#####################
6060

61+
# Signal to bashlog that we are in the terraform shim context.
62+
# All tfenv log output (info, warn) should go to stderr so it does
63+
# not mix with terraform's stdout and break piped commands like:
64+
# terraform version -json | jq
65+
export TFENV_SHIM_MODE=1;
66+
6167
log 'debug' "program=\"${0##*/}\"";
6268

6369
declare tfenv_path="${TFENV_ROOT}/bin/tfenv";

lib/bashlog.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@ function log() {
136136
# Standard Output (Pretty)
137137
case "${level}" in
138138
'info'|'warn')
139-
echo -e "${std_line}";
139+
if [ "${TFENV_SHIM_MODE:-0}" -eq 1 ]; then
140+
# In shim mode (bin/terraform), all tfenv output goes to stderr
141+
# to avoid corrupting terraform's stdout (e.g. terraform version -json | jq)
142+
echo -e "${std_line}" >&2;
143+
else
144+
echo -e "${std_line}";
145+
fi;
140146
;;
141147
'debug')
142148
if [ "${debug_level}" -gt 0 ]; then

0 commit comments

Comments
 (0)