Open seprich opened 1 year ago
Third option: Whenever terraform
gets the flag -json
then the replacement script installed by tfenv recognizes that the overall output should respect the requested output format. As a result, either produce the output from the actual downloaded terraform only without decorations OR if adding extra output related to the installation then fit that output under extra json object property and output the combined json object.
The following shell scripting example can illustrate a problem, which can surprise the unsuspecting user:
With vanilla terraform the above script will consistently run correctly (assuming terraform and jq are installed) producing the raw version number into the environment variable. However when using tfenv and having auto-install feature switched on with a
.terraform-version
file in the project structure then the above script will fail if tfenv needs to install the required version of terraform. Reason being that tfenv will output non-json text to the same stdout pipe as does terraform.So I have 2 suggestions for improving the situation:
tfenv install
(version implicitly read from the .terraform-version file) before using anyterraform
commands in the scripts. This might be even preferable solution in most cases but it would be good to be documented in the README.