.terraform-version generator for tfenv
tfvergen returns version by parsing required_version
from tf files.
Please download binary from releases page.
Move tfvergen
to your PATH.
$ cd <your terraform directory (*)>
$ cat config.tf
terraform {
required_version = "= 1.0.7"
}
: (omitted)
$ tfvergen > .terraform-version
$ cat .terraform-version
1.0.7
(*): a directory where you run terraform plan/apply
$ find . -type f -name 'config.tf' | xargs -L1 bash -c 'cd $(dirname $1) && tfvergen > .terraform-version' _
If the following values are specified, tfvergen returns the first occurrence.
required_version = ">= 1.0.7, < 1.1.0"
# -> tfvergen returns 1.0.7
This is identical to the tfenv specification.