When using tfenv, terraform executable might resolve to different Terraform versions, depending on the directory where it runs (e.g. via using .terraform-version files).
At the moment, the terraform-fmt check runs terraform fmt from the repository root, and in some cases (e.g. when all Terraform configuration along with .terraform-version is in a subfolder) it might even mean that no valid Terraform version is configured.
Proposed solution
For terraform-fmt check, switch to the directory of the Terraform file we're checking (similarly to what happens in terraform-hclfmt and terraform-validate checks). This will ensure that the right Terraform version is picked up if tools like tfenv are used.
Documentation
TODOs
Please ensure all of these TODOs are completed before asking for a review.
[ ] Ensure the branch is named correctly with the issue number. e.g: feature/new-vpc-endpoints-955 or bug/missing-count-param-434.
[ ] Update the docs.
[x] Keep the changes backward compatible where possible.
Description
Problem
When using
tfenv
,terraform
executable might resolve to different Terraform versions, depending on the directory where it runs (e.g. via using.terraform-version
files). At the moment, theterraform-fmt
check runsterraform fmt
from the repository root, and in some cases (e.g. when all Terraform configuration along with.terraform-version
is in a subfolder) it might even mean that no valid Terraform version is configured.Proposed solution
For
terraform-fmt
check, switch to the directory of the Terraform file we're checking (similarly to what happens in terraform-hclfmt and terraform-validate checks). This will ensure that the right Terraform version is picked up if tools liketfenv
are used.Documentation
TODOs
Please ensure all of these TODOs are completed before asking for a review.
feature/new-vpc-endpoints-955
orbug/missing-count-param-434
.Related Issues