tfenv icon indicating copy to clipboard operation
tfenv copied to clipboard

tfenv doesn't read the required_version from conf.tf

Open itsSaad opened this issue 6 years ago • 6 comments

Problem

I have the following declared in my conf.tf file:

terraform {
  required_version = "0.12.5"

  backend "s3" {
    bucket   = "somebucket"
    region   = "eu-central-1"
    role_arn = "somerole"
  }
}

when I runterraform --version, tfenv does not read the version listed but the version set by /usr/local/Cellar/tfenv/1.0.1/version

Intended Behaviour

I expect tfenv to parse the conf.tf file for required_version to use the right version. I documentation is a bit unclear if this is supported or not(https://github.com/tfutils/tfenv#min-required)

itsSaad avatar Jul 22 '19 14:07 itsSaad

This is not an intended use case. tfenv does not evaluate terraform version declarations. The terraform core version in use is maintained by the .terraform-version file. Whether you place a restriction in your required_version declaration to ensure that your code will not execute if evaluated by an incompatible version is up to you.

Zordrak avatar Jul 24 '19 11:07 Zordrak

I think the documentation may be a bit misleading then: https://github.com/tfutils/tfenv#min-required

// this will detect 0.12.3
terraform {
  required_version  = "<0.12.3, >= 0.10.0"
}

digitalfiz avatar Jul 24 '19 13:07 digitalfiz

@Zordrak while it's not intended, would you be open to a PR?

I think should be fairly easy to tie into #118 (once I finally finish my PR - which I need to finish my work on eslint-plugin-jest first :joy:).

At the very least, this could be used to tie into generating a .terraform-version file (and keeping it updated).

I'm happy to handle maintaining & supporting these new features.

G-Rath avatar Jul 29 '19 06:07 G-Rath

Here and in #118 there's suggestions of a PR contribution. Do you still intend to? I was wrong before when I said it wasn't a use case, as I had entirely forgotten about the min-required work that others contributed.

If you think you can safely improve it, you're welcome to offer it up (with associated test cases).

Otherwise, this and #118 probably ought to be closed for now.

Zordrak avatar Feb 06 '21 19:02 Zordrak

@Zordrak I assume you're referring to me :)

I did actually open #122 as an initial implementation for #118, but closed it as it had not gotten any attention from anyone in over a year.

I don't mind picking this back up and seeing if I can improve on the current logic if you're happy to review the PR, but it might take some time.

G-Rath avatar Feb 06 '21 19:02 G-Rath

The docs suggest a bare version, like:

required_version = "0.12.5"

is parsed as meaning the minimum version required is 0.12.5. (edit: I tested - tfenv version-name errors if .terraform-version and the env var don't exist.)

It would be great IMO if, perhaps as part of parsing >/<, the absence of them (or =) would be treated the same way as if 0.12.5 was specified in a separate .terraform-version file. This is terraform's own behaviour - "0.12.5" means 0.12.5 only, so taking that as a minimum will not work if there is a version available >0.12.5.

OJFord avatar Feb 18 '21 14:02 OJFord