tfenv doesn't read the required_version from conf.tf

Created on 22 Jul 2019  ·  6Comments  ·  Source: tfutils/tfenv

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)

documentation enhancement

Most helpful comment

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"
}

All 6 comments

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.

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"
}

@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.

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 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.

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.

Was this page helpful?
0 / 5 - 0 ratings