@@ -29,6 +29,7 @@ If you are using `pre-commit-terraform` already or want to support its developme
2929* [ Table of content] ( #table-of-content )
3030* [ How to install] ( #how-to-install )
3131 * [ 1. Install dependencies] ( #1-install-dependencies )
32+ * [ 1.1 Custom Terraform binaries and OpenTofu support] ( #11-custom-terraform-binaries-and-opentofu-support )
3233 * [ 2. Install the pre-commit hook globally] ( #2-install-the-pre-commit-hook-globally )
3334 * [ 3. Add configs and hooks] ( #3-add-configs-and-hooks )
3435 * [ 4. Run] ( #4-run )
@@ -67,7 +68,7 @@ If you are using `pre-commit-terraform` already or want to support its developme
6768### 1. Install dependencies
6869
6970* [ ` pre-commit ` ] ( https://pre-commit.com/#install ) ,
70- <sub ><sup >[ ` terraform ` ] ( https://www.terraform.io/downloads.html ) ,
71+ <sub ><sup >[ ` terraform ` ] ( https://www.terraform.io/downloads.html ) or [ ` opentofu ` ] ( https://opentofu.org/docs/intro/install/ ) ,
7172 <sub ><sup >[ ` git ` ] ( https://git-scm.com/downloads ) ,
7273 <sub ><sup >[ BASH ` 3.2.57 ` or newer] ( https://www.gnu.org/software/bash/#download ) ,
7374 <sub ><sup >Internet connection (on first run),
@@ -77,17 +78,31 @@ If you are using `pre-commit-terraform` already or want to support its developme
7778 <sub ><sup >Some basic physical laws,
7879 <sub ><sup >Hope that it all will work.
7980 </sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ></sup ></sub ><br ><br >
80- * [ ` checkov ` ] ( https://github.com/bridgecrewio/checkov ) required for ` terraform_checkov ` hook.
81- * [ ` terraform-docs ` ] ( https://github.com/terraform-docs/terraform-docs ) required for ` terraform_docs ` hook.
82- * [ ` terragrunt ` ] ( https://terragrunt.gruntwork.io/docs/getting-started/install/ ) required for ` terragrunt_validate ` hook.
83- * [ ` terrascan ` ] ( https://github.com/tenable/terrascan ) required for ` terrascan ` hook.
84- * [ ` TFLint ` ] ( https://github.com/terraform-linters/tflint ) required for ` terraform_tflint ` hook.
85- * [ ` TFSec ` ] ( https://github.com/liamg/tfsec ) required for ` terraform_tfsec ` hook.
86- * [ ` Trivy ` ] ( https://github.com/aquasecurity/trivy ) required for ` terraform_trivy ` hook.
87- * [ ` infracost ` ] ( https://github.com/infracost/infracost ) required for ` infracost_breakdown ` hook.
88- * [ ` jq ` ] ( https://github.com/stedolan/jq ) required for ` terraform_validate ` with ` --retry-once-with-cleanup ` flag, and for ` infracost_breakdown ` hook.
89- * [ ` tfupdate ` ] ( https://github.com/minamijoyo/tfupdate ) required for ` tfupdate ` hook.
90- * [ ` hcledit ` ] ( https://github.com/minamijoyo/hcledit ) required for ` terraform_wrapper_module_for_each ` hook.
81+ * [ ` checkov ` ] ( https://github.com/bridgecrewio/checkov ) required for ` terraform_checkov ` hook
82+ * [ ` terraform-docs ` ] ( https://github.com/terraform-docs/terraform-docs ) required for ` terraform_docs ` hook
83+ * [ ` terragrunt ` ] ( https://terragrunt.gruntwork.io/docs/getting-started/install/ ) required for ` terragrunt_validate ` hook
84+ * [ ` terrascan ` ] ( https://github.com/tenable/terrascan ) required for ` terrascan ` hook
85+ * [ ` TFLint ` ] ( https://github.com/terraform-linters/tflint ) required for ` terraform_tflint ` hook
86+ * [ ` TFSec ` ] ( https://github.com/liamg/tfsec ) required for ` terraform_tfsec ` hook
87+ * [ ` Trivy ` ] ( https://github.com/aquasecurity/trivy ) required for ` terraform_trivy ` hook
88+ * [ ` infracost ` ] ( https://github.com/infracost/infracost ) required for ` infracost_breakdown ` hook
89+ * [ ` jq ` ] ( https://github.com/stedolan/jq ) required for ` terraform_validate ` with ` --retry-once-with-cleanup ` flag, and for ` infracost_breakdown ` hook
90+ * [ ` tfupdate ` ] ( https://github.com/minamijoyo/tfupdate ) required for ` tfupdate ` hook
91+ * [ ` hcledit ` ] ( https://github.com/minamijoyo/hcledit ) required for ` terraform_wrapper_module_for_each ` hook
92+
93+
94+ #### 1.1 Custom Terraform binaries and OpenTofu support
95+
96+ It is possible to set custom path to ` terraform ` binary.
97+ This makes it possible to use [ OpenTofu] ( https://opentofu.org ) binary ` tofu ` instead of ` terraform ` .
98+
99+ How binary discovery works and how you can redefine it (first matched takes precedence):
100+
101+ 1 . Check if per hook configuration ` --hook-config=--tf-path=<path_to_binary_or_binary_name> ` is set
102+ 2 . Check if ` PCT_TFPATH=<path_to_binary_or_binary_name> ` environment variable is set
103+ 3 . Check if ` TERRAGRUNT_TFPATH=<path_to_binary_or_binary_name> ` environment variable is set
104+ 4 . Check if ` terraform ` binary can be found in the user's $PATH
105+ 5 . Check if ` tofu ` binary can be found in the user's $PATH
91106
92107<details ><summary ><b >Docker</b ></summary ><br >
93108
@@ -120,17 +135,18 @@ To install a specific version of individual tools, define it using `--build-arg`
120135``` bash
121136docker build -t pre-commit-terraform \
122137 --build-arg PRE_COMMIT_VERSION=latest \
123- --build-arg TERRAFORM_VERSION=latest \
138+ --build-arg OPENTOFU_VERSION=latest \
139+ --build-arg TERRAFORM_VERSION=1.5.7 \
124140 --build-arg CHECKOV_VERSION=2.0.405 \
141+ --build-arg HCLEDIT_VERSION=latest \
125142 --build-arg INFRACOST_VERSION=latest \
126143 --build-arg TERRAFORM_DOCS_VERSION=0.15.0 \
127144 --build-arg TERRAGRUNT_VERSION=latest \
128145 --build-arg TERRASCAN_VERSION=1.10.0 \
129146 --build-arg TFLINT_VERSION=0.31.0 \
130147 --build-arg TFSEC_VERSION=latest \
131- --build-arg TRIVY_VERSION=latest \
132148 --build-arg TFUPDATE_VERSION=latest \
133- --build-arg HCLEDIT_VERSION =latest \
149+ --build-arg TRIVY_VERSION =latest \
134150 .
135151```
136152
0 commit comments