terraform-switcher icon indicating copy to clipboard operation
terraform-switcher copied to clipboard

Default version flag added

Open sivaramsajeev opened this issue 1 year ago • 4 comments

This flag will allow us to specify a default version to install which will be useful for the CI systems instead of going into the prompt

sivaramsajeev avatar Oct 11 '22 20:10 sivaramsajeev

@yermulnik In cases where TF_VERSION is already set (say for eg 1.2.4) in the environment, if we add TF_VERSION=1.2.3 tfswitch it'll install version 1.2.3 which is not intended. But tfswitch -d 1.2.3 can really act as a default version. Thanks

sivaramsajeev avatar Oct 12 '22 19:10 sivaramsajeev

@sivaramsajeev Aha, got you. The new option is intended to be a fallback. Though could you please elaborate on how this is expected to work as I might be missing something essential since I'm not familiar with all code bits? From what I see based on example with TF_VERSION: when this Env var is defined (let's suppose its value refers to a non-existing TF version so that fallback should be used) tfswitch triggers installVersion() function, which calls os.Exit(1) on errors (e.g. when requested TF version doesn't exist), which in its turn should interrupt tfswitch execution and hence would not return back into switch statement which handles command line options. What am I missing? 🤔

yermulnik avatar Oct 13 '22 11:10 yermulnik

The --default option is just meant to be the version to be picked up if tfswicth is unable to get the intended version (Either the version is not set using one of the preceding methods OR tfswitch is unable to parse it ). This wont change the original behavior of exiting upon calling invalid version so it's not a fallback in that sense. It's also calling the same installVersion function.

TF_VERSION=x.x.x tfswicth won't act like default because it could potentially end up overriding the intended TF version env var. So if we give this one liner instead of something like tfswitch -d x.x.x, there is a chance that the intended TF version was also set by an environment variable explicitly or sourced during runtime & we end up overriding it with our one-liner.

sivaramsajeev avatar Oct 13 '22 17:10 sivaramsajeev

Either the version is not set using one of the preceding methods OR tfswitch is unable to parse it

Aah, I see now. This is the same as requested in #150 and #165 and actually is, broadly speaking, a programmatic implementation of "hackaround" from https://github.com/warrensbox/terraform-switcher/issues/165#issuecomment-1104400753 (or echo x.x.x | tfswitch to select specific version the same way) Yep, this makes sense to me. You got an approval from me, though @warrensbox and @Jukie would better weigh in to review implementation details.

yermulnik avatar Oct 13 '22 18:10 yermulnik

I am still reviewing this

warrensbox avatar Oct 27 '22 06:10 warrensbox