You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-13Lines changed: 20 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ If you are using `pre-commit-terraform` already or want to support its developme
37
37
*[Available Hooks](#available-hooks)
38
38
*[Hooks usage notes and examples](#hooks-usage-notes-and-examples)
39
39
*[All hooks: Usage of environment variables in `--args`](#all-hooks-usage-of-environment-variables-in---args)
40
+
*[All hooks: Set env vars inside hook at runtime](#all-hooks-set-env-vars-inside-hook-at-runtime)
40
41
*[checkov (deprecated) and terraform_checkov](#checkov-deprecated-and-terraform_checkov)
41
42
*[infracost_breakdown](#infracost_breakdown)
42
43
*[terraform_docs](#terraform_docs)
@@ -283,6 +284,22 @@ Config example:
283
284
284
285
If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` before `pre-commit run`, args will be expanded to `--config=.tflint.hcl --module`.
285
286
287
+
### All hooks: Set env vars inside hook at runtime
288
+
289
+
> All, except deprecated hooks: `checkov`, `terraform_docs_replace`
290
+
291
+
You can specify environment variables that will be passed to the hook at runtime.
292
+
293
+
Config example:
294
+
295
+
```yaml
296
+
- id: terraform_validate
297
+
args:
298
+
- --envs=AWS_DEFAULT_REGION="us-west-2"
299
+
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
300
+
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
301
+
```
302
+
286
303
### checkov (deprecated) and terraform_checkov
287
304
288
305
> `checkov` hook is deprecated, please use `terraform_checkov`.
@@ -614,25 +631,15 @@ Example:
614
631
- --args=-no-color
615
632
```
616
633
617
-
2. `terraform_validate` also supports custom environment variables passed to the pre-commit runtime:
618
-
619
-
```yaml
620
-
- id: terraform_validate
621
-
args:
622
-
- --envs=AWS_DEFAULT_REGION="us-west-2"
623
-
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
624
-
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
625
-
```
626
-
627
-
3. `terraform_validate` also supports passing custom arguments to its `terraform init`:
634
+
2. `terraform_validate` also supports passing custom arguments to its `terraform init`:
628
635
629
636
```yaml
630
637
- id: terraform_validate
631
638
args:
632
639
- --tf-init-args=-lockfile=readonly
633
640
```
634
641
635
-
4. It may happen that Terraform working directory (`.terraform`) already exists but not in the best condition (eg, not initialized modules, wrong version of Terraform, etc.). To solve this problem, you can find and delete all `.terraform` directories in your repository:
642
+
3. It may happen that Terraform working directory (`.terraform`) already exists but not in the best condition (eg, not initialized modules, wrong version of Terraform, etc.). To solve this problem, you can find and delete all `.terraform` directories in your repository:
636
643
637
644
```bash
638
645
echo "
@@ -648,7 +655,7 @@ Example:
648
655
649
656
**Warning:** If you use Terraform workspaces, DO NOT use this workaround ([details](https://github.com/antonbabenko/pre-commit-terraform/issues/203#issuecomment-918791847)). Wait to [`force-init`](https://github.com/antonbabenko/pre-commit-terraform/issues/224) option implementation.
650
657
651
-
5. `terraform_validate` in a repo with Terraform module, written using Terraform 0.15+ and which uses provider `configuration_aliases` ([Provider Aliases Within Modules](https://www.terraform.io/language/modules/develop/providers#provider-aliases-within-modules)), errors out.
658
+
4. `terraform_validate` in a repo with Terraform module, written using Terraform 0.15+ and which uses provider `configuration_aliases` ([Provider Aliases Within Modules](https://www.terraform.io/language/modules/develop/providers#provider-aliases-within-modules)), errors out.
652
659
653
660
When running the hook against Terraform code where you have provider `configuration_aliases` defined in a `required_providers` configuration block, terraform will throw an error like:
0 commit comments