Skip to content

Commit

Permalink
feat: Create different hooks for Terraform and OpenTofu format
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Dec 5, 2024
1 parent 6f4e2a2 commit 4696ed5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
23 changes: 20 additions & 3 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3632,9 +3632,26 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
terraform-format =
{
name = "terraform-format";
description = "Format terraform (`.tf`) files.";
package = tools.terraform-fmt;
entry = "${hooks.terraform-format.package}/bin/terraform-fmt";
description = "Format Terraform (`.tf`) files.";
package = tools.opentofu;
entry =
let
terraform-fmt = pkgs.writeScriptBin "terraform-fmt" ''
#!/usr/bin/env bash
opentofu_or_terraform() {
local bin_dir=${hooks.terraform-format.package}
if [ -f "''${bin_dir}/bin/tofu" ]; then
''${bin_dir}/bin/tofu "$@"
else
''${bin_dir}/bin/terraform "$@"
fi
}
opentofu_or_terraform fmt -check -diff "$@"
'';
in
"${terraform-fmt}/bin/terraform-fmt";
files = "\\.tf$";
};
terraform-validate =
Expand Down
12 changes: 0 additions & 12 deletions nix/terraform-fmt/default.nix

This file was deleted.

3 changes: 2 additions & 1 deletion nix/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
, nodePackages
, ocamlPackages
, opam
, opentofu
, ormolu
, pkgsBuildBuild
, poetry
Expand Down Expand Up @@ -137,6 +138,7 @@ in
mdsh
nil
nixpkgs-fmt
opentofu
ormolu
pre-commit-hook-ensure-sops
poetry
Expand Down Expand Up @@ -185,7 +187,6 @@ in
hpack-dir = callPackage ./hpack-dir { };
hunspell = callPackage ./hunspell { };
purty = callPackage ./purty { purty = nodePackages.purty; };
terraform-fmt = callPackage ./terraform-fmt { };
terraform-validate = callPackage ./terraform-validate { };
tflint = callPackage ./tflint { };
dune-build-opam-files = callPackage ./dune-build-opam-files { dune = dune_3; inherit (pkgsBuildBuild) ocaml; };
Expand Down

0 comments on commit 4696ed5

Please sign in to comment.