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

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

Closed
jdx opened this issue Nov 30, 2024 · 7 comments · Fixed by #3380
Closed

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

jdx opened this issue Nov 30, 2024 · 7 comments · Fixed by #3380
Labels

Comments

@jdx
Copy link
Owner

jdx commented Nov 30, 2024

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 jdx added the bug label Nov 30, 2024
@jdx
Copy link
Owner Author

jdx commented Nov 30, 2024

@jdx
Copy link
Owner Author

jdx commented Nov 30, 2024

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
Copy link

rymancl commented Dec 2, 2024

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.

@jdx
Copy link
Owner Author

jdx commented Dec 4, 2024

well right now with the aqua backend it isn't going to look for this file at all, so you at least won't see that error

@suzuki-shunsuke
Copy link

  1. I have some concern about making aqua support .terraform-version.

So I'm not sure if aqua supports .terraform-version.

  1. I'm not familiar with mise, so I'm not sure why mise requires aqua to support .terraform-version.

mise doesn't execute aqua. mise just uses aqua-registry.
So in my understanding, mise parses .terraform-version and gets the version, and gets aqua-registry and installs Terraform.

About expr, the expression used in registry.yaml for Terraform is very simple.

https://github.com/aquaproj/aqua-registry/blob/6c5fd6a171c22c56a265a9f9b037e6014c68930d/pkgs/hashicorp/terraform/registry.yaml#L11

    version_constraint: semver(">= 1.0.2")

@jdx
Copy link
Owner Author

jdx commented Dec 5, 2024

sorry I think my question got a bit complex. Let me simplify—you got most of it right but a couple of things I think got confused.

My main question is whether or not you plan to support .terraform-version in aqua. (it sounds like you do not plan on that right now). If you don't, I will need to add the ability for mise to use .terraform-version while using the aqua registry inside of mise.

However if you were planning to support .terraform-version I think we could figure out what that configuration would look like in the aqua registry. Of course mise would not call aqua for that, but presumably there would be some configuration in registry.yaml to define that.

That's why I brought up expr, because I think it could be a solution for that. We could have these properties in the registry for idiomatic files in registry.yaml used by both mise and aqua:

idiomatic_file_names: [".terraform-versions"] # equivalent of https://github.com/asdf-community/asdf-hashicorp/blob/master/bin/list-legacy-filenames 
idiomatic_parse: |
  body | trimPrefix "^"

Anyhow, I think the right plan for mise right now is to implement this logic inside of mise and not in the registry, however if and when you do want to come up with a way to implement this in the aqua registry that would be my proposal for it.

Also for what it's worth, mise never supported semver versions in .terraform-version. I'll post on your thread about that just for your reference to know what the experience has been like.

jdx added a commit that referenced this issue Dec 5, 2024
jdx added a commit that referenced this issue Dec 5, 2024
@jdx jdx closed this as completed in #3380 Dec 6, 2024
@jdx jdx closed this as completed in 404c9f4 Dec 6, 2024
@suzuki-shunsuke
Copy link

Ah, I see. Thank you for your explanation!
It sounds reasonable.

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

Successfully merging a pull request may close this issue.

3 participants