tfutils / tfenv

Terraform version manager
MIT License
4.43k stars 450 forks source link

latest-allowed installs absolute latest (beta), not honoring required version #375

Open dalmadebreceni opened 1 year ago

dalmadebreceni commented 1 year ago

Scans terraform files for required version, finds it. Then ignores it, switches to "version=latest" instead of latest of required (major) version. tfenv/libexec/tfenv-install latest-allowed ->

[...]
+ version_requested=latest-allowed
+ [[ -n latest-allowed ]]
+ log debug 'Version Requested: latest-allowed'
+ '[' debug '!=' debug ']'
+ [[ latest-allowed =~ ^v.*$ ]]
+ [[ latest-allowed =~ ^min-required$ ]]
+ [[ latest-allowed =~ ^latest-allowed$ ]]
+ log debug 'Detecting latest allowable version...'
[...]
++ grep -h required_version [...]
+ version_spec='~> 1.2'
++ echo '~> 1.2'
++ sed -E 's/[^0-9.]+//'
+ version_num=1.2
+ log debug 'Using 1.2 from version spec: ~> 1.2'
+ '[' debug '!=' debug ']'
+ case "${version_spec}" in
++ echo 1.2
++ rev
++ cut -d. -f2-
++ rev
+ version_without_rightmost=1
+ version_requested='latest:^1'
+ log debug 'Determined the requested version to be: latest:^1'
+ '[' debug '!=' debug ']'
+ [[ latest:^1 =~ ^latest:.*$ ]]
+ version=latest
+ regex='^1'
+ log debug 'Version uses latest keyword with regex: ^1'
+ '[' debug '!=' debug ']'
+ echo 'latest:^1'
Terraform v1.4.0-alpha20221207 is already installed
dalmadebreceni commented 1 year ago

this fails because it cuts the version to 1, so works only if the terraform version is in the form of having 2 dots (aka 1.2.), but not with 1 dot (1.2).

sspans-sbp commented 8 months ago

Would it be an option to introduce latest-allowed-alpha and have that tag include pre-release versions? That would make latest-allowed and latest:^1. a lot more useful for most normal users.

Now I'm jumping through hoops to make tfenv not install alpha versions.

Michenux commented 4 months ago

tfenv latest-allowed should align with terraform behaviour, in the documentation : "A prerelease version can be selected only by an exact version constraint (the = operator or no operator). Prerelease versions do not match inexact operators such as >=, ~>, etc."