When using terraform-switcher, the tool determines which Terraform version to use based on a specific hierarchy of configuration sources. If multiple versions are defined, the method with the highest precedence wins.
Precedence order (from lowest to highest):
- Global Config: The
version parameter in $HOME/.tfswitch.toml. - Local Config File: A
.tfswitchrc file containing the version as a string. - Version File: A
.terraform-version file containing the version as a string. - Terraform Module: The
required_version constraint within your Terraform root module. - Terragrunt/Root Config: The
terraform_version_constraint parameter in terragrunt.hcl or root.hcl. - Environment Variable: The
TF_VERSION environment variable. - CLI Argument: The version explicitly provided as a command line argument to the
terraform-switcher command.
| Order | Method | |
| ----- | ----- | |
| 1 | `$HOME/.tfswitch.toml` (`version` parameter) | |
| 2 | `.tfswitchrc` (version as a string) | |
| 3 | `.terraform-version` (version as a string) | |
| 4 | Terraform root module (`required_version` constraint) | |
| 5 | `terragrunt.hcl` or `root.hcl` (`terraform_version_constraint` parameter) | |
| 6 | Environment variable (`TF_VERSION`) | |
| 7 | Version provided as command line argument |