-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Support default tofu version #41
Conversation
Hi @orbitz thank you for MR! |
LGTM; As @Nmishin said, it would be good idea to fix tests if you have capacity for that. Big thanks for contribution |
I'm not quite sure how to read the output here, I don't see a failure. Any ideas how to track it down? |
21d4555
to
b9b5d85
Compare
I added some explicit logging statements to the tests which will hopefully narrow it down, but need the tests to run here. |
lib/tofuenv-version-name.sh
Outdated
&& log 'debug' "TOFUENV_VERSION specified in TOFUENV_VERSION_FILE: ${TOFUENV_VERSION}"; | ||
TOFUENV_VERSION_SOURCE="${TOFUENV_VERSION_FILE}"; | ||
else | ||
TOFUENV_VERSION="${TOFUENV_TOFU_DEFAULT_VERSION:-"latest"}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @orbitz, thanks for your contribution!
The default value should be empty if no version is set in TOFUENV_TOFU_DEFAULT_VERSION
variable. Otherwise, it will always trigger the installation of the latest version when tofuenv version-name command is triggered (which is not supposed to trigger installation). This is what causes the tests' failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this what the documentation for tofuenv install
says should happen, though?
If no parameter is passed, the version to use is resolved automatically via TOFUENV_TOFU_VERSION environment variable or .opentofu-version files, in that order of precedence, i.e. TOFUENV_TOFU_VERSION, then .opentofu-version. The default is latest if none are found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but tofuenv install
already works this way.
It calls tofuenv-resolve-version
first - https://github.com/tofuutils/tofuenv/blob/main/libexec/tofuenv-install#L67, and then installs latest
if no other version has been specified - https://github.com/tofuutils/tofuenv/blob/main/libexec/tofuenv-resolve-version#L97
Actually, tofuenv install
command doesn't use tofuenv-version-name.sh
script at all (tofuenv version-name
command just checks and returns opentofu version currently used in a current directory, so it should not trigger any installation). So to add the support of a new TOFUENV_TOFU_DEFAULT_VERSION
variable during installation process, you'll need to add a correspoding change to libexec/tofuenv-install script as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that tofuenv version-name
command is not described in the documentation, we'll add it there. But the output of tofuenv help
returns the following description:
version-name Print current version of OpenTofu
So this command should not trigger any installation and should just show the current OpenTofu version. If it's set to latest
by default (when no version is specified in TOFUENV_TOFU_VERSION
environment variable, in .opentofu-version
file, in version
file, or in TOFUENV_TOFU_DEFAULT_VERSION
variable), it's illogical, when a user doesn't have any OpenTofu installed. Moreover, setting it to latest
by default if no version is specified anywhere will trigger OpenTofu installation, when a user just wants to check if they have any versions installed, but not to install anything.
So if no OpenTofu version is specified in the list of sources to check, it should remain empty when calling tofuenv version-name
.
However, you're right that tofuenv install
command should install latest
version if no version is specified - but it's set in a different script, to which I attached the link above. That would be great if you could add support for the TOFUENV_TOFU_DEFAULT_VERSION
there 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation. After looking over the files you mentioned I see my mistake.
At the same time, I wonder if perhaps the behaviour of this change is correct? It depends on what one expects tofuenv install
to do. In my case, I expected it to install whatever version the current directory specified. But if the actual functionality is to install the specified version, or latest, then it is correct (although my README update is wrong).
As it is now, the current behavior does what I want in that tofu ...
will install the version specified in the directory or fallback to an environment variable. However, as you mention, it does not for tofu install
.
What would you like the behaviour of these to operations to be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, as you mentioned, tofuenv install
command first checks if any opentofu version is set in TOFUENV_TOFU_VERSION
environment variable, and then in .opentofu-version
file, and if no versions are found - uses latest
.
But as you mentioned in README, it would be great to support default version setting. In this case, tofuenv install
command without any version passed will check the following sources:
- TOFUENV_TOFU_VERSION environment variable
- .opentofu-version files
- TOFUENV_TOFU_DEFAULT_VERSION
- The default of
latest
.
So we will still have latest
version if no version was specified, but also there will be an ability to set a default one using TOFUENV_TOFU_DEFAULT_VERSION
environment variable in, for ex., some CI/CD pipeline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Just confirming the desired behaviour. I'll finish this change it ASAP
@orbitz could you please also include changelog file to your MR, for example as here: https://github.com/tofuutils/tofuenv/pull/50/files this will allow us to have a beautiful history in CHANGELOG.md |
f538578
to
09520a4
Compare
This is ready for review again. |
Looks like this is failing due to uninstall again. After some debugging, the cause is because of my change on any What do you think are the appropriate semantics here? |
e20310a
to
9724e73
Compare
@@ -56,7 +56,7 @@ function test_uninstall() { | |||
tofuenv install "${v}" || return 1; | |||
tofuenv uninstall "${v}" || return 1; | |||
log 'info' 'Confirming uninstall success; an error indicates success:'; | |||
check_active_version "${v}" && return 1 || return 0; | |||
env TOFUENV_AUTO_INSTALL=false "${TOFUENV_ROOT}/bin/tofu" version && return 1 || return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bypass the helper function here, but this guarantees that tofu
fails if the version is not installed.
Hello, would it be possible to close the loop on this soon? I see a test is failing but it looks unrelated to my change. |
Hello @orbitz ! Thank you for continuing working on this feature, I apologize it took so long to review your changes.
Could you please not set a version to be 'latest' here by default? This may be confusing for the people who just installed tofuenv and haven't yet installed any tofu versions. |
And also could you please not update main CHANGELOG.md file (it's updated automatically), but add a new file in a .changelog folder, describing your changes? The example can be found here - f5d92f6 |
&& log 'debug' "TOFUENV_VERSION specified in TOFUENV_VERSION_FILE: ${TOFUENV_VERSION}"; | ||
TOFUENV_VERSION_SOURCE="${TOFUENV_VERSION_FILE}"; | ||
else | ||
TOFUENV_VERSION="${TOFUENV_TOFU_DEFAULT_VERSION:-"latest"}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continuing my comment in the discussion, I suggest setting the version to an empty string by default, ex.
TOFUENV_VERSION="${TOFUENV_TOFU_DEFAULT_VERSION:-""}";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anastasiiakozlova245 Won't that mean that tofuenv exec
will not have the correct/consistent behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbitz could you please clarify what you mean by not having a consistent behaviour? As stated in the docs, tofuenv install
command will still install the latest version if no version is specified, since it doesn't use this particular script. However, tofuenv version-name
should show the version of tofu
currently installed/set in configs (.opentofu-version
file, env variables). If tofuenv
is just installed, and no version is set anywhere, why should it print the latest one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I'm confused bu but tofuenv-exec
which is called from the tofu
wrapper does use this function. I would expect it to have the semantics as tofuenv install
. If I change line 18 to :-""
then if no version is found it will look for version "", which will never exist. For example, in main
, if I have no version information set:
> ./bin/tofu version
cat: /usr/home/orbitz/projects/terrateam/tofuenv/version: No such file or directory
Version could not be resolved (set by /usr/home/orbitz/projects/terrateam/tofuenv/version or tofuenv use <version>)
However, with this change:
> ./bin/tofu version
version '1.6.1' is not installed (set by /usr/home/orbitz/projects/terrateam/tofuenv/version). Installing now as TOFUENV_AUTO_INSTALL==true
Installing OpenTofu v1.6.1
Downloading release tarball from https://github.com/opentofu/opentofu/releases/download/v1.6.1/tofu_1.6.1_freebsd_amd64.zip
##################################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://github.com/opentofu/opentofu/releases/download/v1.6.1/tofu_1.6.1_SHA256SUMS
Not instructed to use Local GPG (/usr/home/orbitz/projects/terrateam/tofuenv/use-{gpgv,gnupg}), skipping GnuPG signature verification
Installation of tofu v1.6.1 successful. To make this your default version, run 'tofuenv use 1.6.1'
OpenTofu v1.6.1
on freebsd_amd64
This is the behaviour I would expect, is this not the behaviour you would expect? If so, what is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbitz I believe when you call ./bin/tofu version
, it shouldn't trigger an automatic installation of a latest package. version
command is not supposed to install anything, it should just provide an information about the version installed or set anywhere in configs. And if it's not - then returning an error is expected.
@Nmishin what do you think the correct behaviour would be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are a few things to consider:
- Even if you don't think an install should happen, I believe that calling
tofu foo
should get the same version as when you calledtofuenv install
. So iftofuenv install
defaults tolatest
if no version information is set, thentofu foo
should get that value as well. - As it stands now, if you DO set any version information then
tofu foo
will install that version if it is not already installed. Line 18 just guarantees that it is matches thetofuenv install
version discovery algorithm. - As the code stands now, whether or not
tofu foo
installs something depends on the value of the auto install variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just bumping this discussion.
254082a
to
7818694
Compare
7818694
to
b514173
Compare
Hello, anything I can do to move this change along? |
hello @orbitz i will deep into your changes in a couple of days! |
It looks like this pull request is slowly dying. It's been around for weeks and now there is a conflict. Is there any desire to pull this feature in? If not, we can close this. |
hi @orbitz we discussed internally about this, and we are ok with variable TOFUENV_TOFU_DEFAULT_VERSION, Please update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please also rename 47.txt to 41.txt - filename should point to pull request number
@Nmishin Depending on where you mean, I don't think setting this to Setting the default |
Decided to close this, it looks like tenv has included the functionality I want and it works across every toolchain. Will be moving to tenv in the future |
Support an environment variable for the default version of OpenTofu if no other version information is found.
Being an environment variable gives more flexibility than the existing ``${TOFUENV_CONFIG_DIR}/version` solution, in that you can easily set the environment variable for the process you are running.
This resolves #34