Quipper provides some products that consist of different infrastructures (AWS VPCs) and we use Terraform to build them.
Also, our team manages Terraform files (
.tfvars) for a product as a GitHub repository such as
quipper/product1-terraform and each repository uses different versions of Terraform. For example, one product uses
0.6.16 but another uses
In this situation, we have to be careful to run
terraform commands with the correct version because a
.tfstate file generated by an incorrect version might not be compatible, especially between version 0.6 and 0.7.
In order to prevent such an incident, we use tfenv, which is an open source version manager of Terraform.
It’s really easy! We just check out the repository and add
tfenv/bin to our
$ git clone https://github.com/kamatama41/tfenv.git ~/.tfenv $ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
We can install a specific version of Terraform with
tfenv install <version>
$ tfenv install 0.7.3
It’s a feature similar to
.ruby-version of rbenv. tfenv detects
.terraform-version on our repository root and uses the version in the file preferentially. So we can use only one version by putting the file into each repository.
$ cat .terraform-version 0.6.16 $ terraform --version Terraform v0.6.16 Your version of Terraform is out of date! The latest version is 0.7.3. You can update by downloading from www.terraform.io $ echo 0.7.3 > .terraform-version $ terraform --version Terraform v0.7.3
tfenv makes us happy when we use Terraform with multiple users or on multiple environments.