Skip to content

Commit b68b780

Browse files
authored
Merge pull request #668 from veselyn/terraform-validate-package
feat(terraform-validate): support both opentofu and terraform
2 parents 09e45f2 + 0d3698e commit b68b780

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,16 @@ use nix
470470

471471
### Terraform
472472

473-
- `terraform-format`: built-in formatter (using [OpenTofu](https://opentofu.org/)'s [`fmt`](https://opentofu.org/docs/cli/commands/fmt/))
474-
- `terraform-validate`: built-in validator (using [OpenTofu](https://opentofu.org/)'s [`validate`](https://opentofu.org/docs/cli/commands/validate/))
473+
- `terraform-format`: built-in formatter (using
474+
[OpenTofu](https://opentofu.org/)'s
475+
[`fmt`](https://opentofu.org/docs/cli/commands/fmt/) or
476+
[Terraform](https://developer.hashicorp.com/terraform)'s
477+
[`fmt`](https://developer.hashicorp.com/terraform/cli/commands/fmt))
478+
- `terraform-validate`: built-in validator (using
479+
[OpenTofu](https://opentofu.org/)'s
480+
[`validate`](https://opentofu.org/docs/cli/commands/validate/)
481+
[Terraform](https://developer.hashicorp.com/terraform)'s
482+
[`validate`](https://developer.hashicorp.com/terraform/cli/commands/validate))
475483
- [tflint](https://github.com/terraform-linters/tflint)
476484

477485
### TOML

modules/hooks.nix

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,8 +4126,24 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
41264126
{
41274127
name = "terraform-validate";
41284128
description = "Validates terraform configuration files (`.tf`).";
4129-
package = tools.terraform-validate;
4130-
entry = "${hooks.terraform-validate.package}/bin/terraform-validate";
4129+
package = tools.opentofu;
4130+
entry =
4131+
let
4132+
terraform-validate = pkgs.writeScriptBin "terraform-validate" ''
4133+
#!/usr/bin/env bash
4134+
set -x
4135+
for arg in "$@"; do
4136+
dirname "$arg"
4137+
done \
4138+
| sort \
4139+
| uniq \
4140+
| while read dir; do
4141+
${lib.getExe hooks.terraform-validate.package} -chdir="$dir" init
4142+
${lib.getExe hooks.terraform-validate.package} -chdir="$dir" validate
4143+
done
4144+
'';
4145+
in
4146+
"${terraform-validate}/bin/terraform-validate";
41314147
files = "\\.(tf(vars)?|terraform\\.lock\\.hcl)$";
41324148
excludes = [ "\\.terraform/.*$" ];
41334149
require_serial = true;

nix/terraform-validate/default.nix

Lines changed: 0 additions & 14 deletions
This file was deleted.

nix/tools.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ in
232232
cabal2nix-dir = callPackage ./cabal2nix-dir { };
233233
hpack-dir = callPackage ./hpack-dir { };
234234
hunspell = callPackage ./hunspell { };
235-
terraform-validate = callPackage ./terraform-validate { };
236235
tflint = callPackage ./tflint { };
237236
dune-build-opam-files = callPackage ./dune-build-opam-files {
238237
dune = dune_3;

0 commit comments

Comments
 (0)