gruntwork-io / pre-commit

A collection of pre-commit hooks used by Gruntwork tools
https://gruntwork.io/
Apache License 2.0
484 stars 155 forks source link

Switch to file directory for terraform-fmt check #97

Open tonyo opened 1 year ago

tonyo commented 1 year ago

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, 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.

Related Issues