Tfenv: Don't change tfenv version globally when entering a directory with a .terraform-version

Created on 11 Oct 2019  ·  4Comments  ·  Source: tfutils/tfenv

Didn't know how to resume it better x)

If you set the tfenv version to 0.11.14 and enter a directory with a .terraform-version that points to 0.12.4, it changes the tfenv version globally. That means that when you go outside that directory, it doesn't revert the tfenv version to 0.11.14, it maintains the 0.12.4 version. I think it should do it as the default behaviour.

PD: tfenv it's very cool, thanks for your work!

Most helpful comment

On mac, the mechanism of /usr/local/bin/terraform creates this problem. tfenv should be setting PATH or similar for the right version of terraform in the environment rather than creating symlinks or other files on the FS which acts globally.

Doing such things means its not possible to run concurrent terraform invocations with different versions using this tool.

(Sure you knew that anyway, but thats my problem - which means i cant use tfenv at all for CI)

All 4 comments

Think this ties into another ticket or so addressing how we deal with version files and the use command. It's on the list.

On mac, the mechanism of /usr/local/bin/terraform creates this problem. tfenv should be setting PATH or similar for the right version of terraform in the environment rather than creating symlinks or other files on the FS which acts globally.

Doing such things means its not possible to run concurrent terraform invocations with different versions using this tool.

(Sure you knew that anyway, but thats my problem - which means i cant use tfenv at all for CI)

Not addressing this (environment manipulation instead of system-level default) in v2.0.0 as 2.0.0 is a significant rewrite that is already stable; will perhaps look at it for v2.1.0.

Two solutions for CI configurations where parallel execution is required:

  1. You can use .terraform-version files. No use command is required, just execute terraform with a .terraform-version file that is unique to the CI execution.
  2. Clone the TFENV_ROOT within the CI execution environment as you can have as many tfenv installations as you like, and the one your path points at is unaffected by others. tfenv total size is incredibly small.

See https://github.com/tfutils/tfenv/tree/v2.0.0-beta1 for the 2.0.0 release candidate. Now does not overwrite .terraform-version files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Constantin07 picture Constantin07  ·  8Comments

dkolb picture dkolb  ·  6Comments

ibakayoko picture ibakayoko  ·  6Comments

sthristov picture sthristov  ·  5Comments

itsSaad picture itsSaad  ·  6Comments