jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
10.39k stars 297 forks source link

terraform idiomatic files don't work with aqua (`.terraform-version`) #3311

Open jdx opened 2 days ago

jdx commented 2 days ago

this is a problem for all aqua tools I'm surprised nobody has reported but I just realized it. I haven't actually tested this but I don't see why it wouldn't be the case knowing how things work. aqua has no support for idiomatic files like .terraform-version and I don't even know if that's something aqua would be interested in adding. I'm calling out terraform here because it's probably the most popular tool that I know uses idiomatic files.

In the meantime if you want this, just install the asdf plugin manually, disable the aqua backend, or alias terraform to asdf:https://github.com/asdf-community/asdf-hashicorp.


(the rest of this is addressed to @suzuki-shunsuke specifically)

these files sometimes are just parsed as raw versions, e.g.: .node-version can just be 20.0.0 but in the case of terraform, the logic is fairly complex: https://github.com/asdf-community/asdf-hashicorp/blob/master/bin/parse-legacy-file

I don't know if you've considered supporting files like this. I know in asdf they called them "legacy version files" which to me implies that they didn't want people to use them. I think they're great though and I know users are quite fond of them since it allows project maintainers to not specify what tool manager their developers use. I think this is a feature in mise that certainly has been good for my project.

I think to support this we could add a field to specify the names of the files, then an optional field using expr to parse the files like this:

idiomatic_file_names: [".terraform-versions"] # equivalent of https://github.com/asdf-community/asdf-hashicorp/blob/master/bin/list-legacy-filenames 
idiomatic_parse: "..." # this would be quite complex but would be equivalent to https://github.com/asdf-community/asdf-hashicorp/blob/master/bin/parse-legacy-file

I had to build a rust version of expr which wasn't easy and only partially complete but it's complete enough that this shouldn't be that hard to support if this were available.

anyhow lmk. I think if you aren't interested I'll probably need to either fork the aqua registry or maintain this information inside the mise codebase somehow, either is fine but not as ideal.

jdx commented 2 days ago

oh awesome, looks like you have talked about this:

jdx commented 2 days ago

idk how I feel about asdf-hashicorp supporting ASDF_HASHICORP_TERRAFORM_VERSION_FILE as a way to customize the list behavior. That wouldn't even work with mise very well since mise caches the results of list_legacy_versions forever so it would need to have been set before the plugin was installed.

Looking at souregraph this does not appear to be a commonly used configuration. I'm inclined to say we should not support that feature.

rymancl commented 11 hours ago

Ha, I actually just came here to ask about this. I've ignored it for ages and finally got to the point where it's being a nuisance in my daily work. We use tfenv in all our pipelines, but locally I use mise.

Error: 
   0: error parsing config file: ~/path/to/my/terraform/code/.terraform-version
   1: invalid tool version request: latest:^1.10

Location:
   src/toolset/tool_version_request.rs:73

Version:
   2024.6.6 macos-arm64 (409d6e4 2024-06-20)

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

It would be cool to support this, but I'm sure it isn't trivial. I'd even settle for a way to ignore certain "version files" (maybe this exists already, I didn't dig too much).

EDIT: A main problem this causes locally: I have my VS Code set to run terraform fmt on save. Since mise throws this error, all terraform fmt commands technically throw an error, therefore nothing gets auto-formatted.