terraform-switcher
terraform-switcher copied to clipboard
Default version flag added
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
@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 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? 🤔
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.
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.
I am still reviewing this