-
Notifications
You must be signed in to change notification settings - Fork 36
add terraform-local version when using version flag #84
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
Conversation
|
|
||
| ## Change Log | ||
|
|
||
| * v0.24.0: Add support to return `terraform-local` version when calling `tflocal -version` and fix AWS provider detection |
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.
this doesn't sound clear... lmk if you find something better, I'd happily take any suggestion 😅
cloutierMat
left a comment
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.
Awesome! Thanks for taking this initiative to solve this pain point and your diligence to not break users possible flows in the process. more information is always better!
I only left a question regarding the test. It seems that there might be an extra copy paste comment, unless I am missing something 😄
|
|
||
| ## Change Log | ||
|
|
||
| * v0.24.0: Add support to return `terraform-local` version when calling `tflocal -version` and fix AWS provider detection |
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.
Thanks for adding the previous pr changelog as well! 🙏
| def get_tf_local_version(): | ||
| from importlib.metadata import version | ||
| return version("terraform-local") |
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 agree that this seems safe. It will find the version that is currently available in the venv, so we won't have issues with multiple install of tflocal.
I have tested install with pipx, with pip in a venv and my hybrid dev env, and all seem to give proper result. 👍
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.
awesome, thanks a lot for taking the time to test extra scenarios 🙏
| except Exception: | ||
| pass |
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.
🎉 Hurray for extra safety here! 🚀
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.
thanks! made me think I'll update those to use contextlib.suppress, but this will be for a follow up 👌
tests/test_apply.py
Outdated
| return subprocess.check_output(cmd, **kwargs) | ||
|
|
||
| with tempfile.TemporaryDirectory(delete=True) as temp_dir: | ||
| # we need the `terraform init` command to create a lock file, so it cannot be a `DRY_RUN` |
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.
Is that a forgotten copy paste? I fail to see where the init or the dry run would impact the version command 🤔
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.
it is indeed, my bad 😅 will update
This PR now returns the version of
terraform-localwhen runningtflocal -v(or--version,-version, all accepted by Terraform).This was sometimes an issue when users had a global installation of
tflocaland one in a virtual environment, and only updated one of them. It was hard to know which version you'd be calling/using.We are printing to
stderrto avoid breaking existing user setup maybe relying ontflocal --versionreturning the underlying Terraform version unmodified.It is not trivial to get the version without directly parsing the
setup.cfgfile, or changing the setup itself to create a__version__variable somewhere in the code to be imported.Relying on
from importlib.metadata import versionseems safe, but I'm not sure if it could import a different version than the one that is being called right now... 🤔 I doubt itThis seems to be the preferred way: https://packaging.python.org/en/latest/discussions/versioning/#runtime-version-access