Skip to content
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

Feature request: Support latest:<regex> syntax #14

Open
smiller171 opened this issue Mar 23, 2022 · 2 comments
Open

Feature request: Support latest:<regex> syntax #14

smiller171 opened this issue Mar 23, 2022 · 2 comments

Comments

@smiller171
Copy link
Contributor

tfenv supports strings like latest:^1. in order to grab the most recent version that matches a regex constraint. This is useful for keeping within a particular major or minor version, while continuing to get patch and security updates without needing to manually change your .terraform-version every time.

I'd love to see chtf support this syntax as well, if only to maintain compatibility with existing .terraform-version files

@tmatilai
Copy link
Collaborator

Thanks for the suggestion!

In the spirit of the chruby, the idea has been to keep the helper script as simple and lightweight. So far even the .terraform-version support has been left out and only an example implementation is given the README.

The biggest challenge of implementing "native" support for .terraform-version or even command line wildcards etc., is that how to specify the latest matching version. Currently chtf only knows about already installed versions, but as a user I would probably like to use the latest matching released version instead, and auto-install it if needed. And this would require querying the available versions. And the two installation methods would require different solutions.

Support for selecting only local versions is simpler, but I'm not sure if that would be enough?

All that said, I use myself a Fish config to use the latest installed version by default if the specified version is latest:

if test -f $HOME/.terraform-version
    and type -q chtf
    set -l v (cat $HOME/.terraform-version)
    if test $v = "latest"
        set v (chtf | tr -d ' *' | sort -V | tail -1)
    end
    chtf $v
end

It should be fairly easy to implement similar Bash/ZSH version should, or to add more logic for filtering the matching version.

What do you think? How would you like the whole thing to work? 🙂

As always, I seem to be a tight on free hacking time, but I'm happy to help and improve the functionality and docs up to certain point. And of course I'm open for PRs for those remote version helpers, maybe as separate command(s).

@smiller171
Copy link
Contributor Author

I hadn't looked closely enough to realize that the entire logic for parsing the .terraform-version file was in that little example script, with nothing built into the tool itself.

I think even just looking at locally installed versions would be helpful. Maybe I'll find the time to hack away at something myself. If I do I'll open a PR against the Readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants