File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
6167log ' debug' " program=\" ${0##*/ } \" " ;
6268
6369declare tfenv_path=" ${TFENV_ROOT} /bin/tfenv" ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments