diff --git a/README.md b/README.md index ac188501..2a0821e1 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ clang-format supports. ### Terraform - `terraform-format`: built-in formatter (using [OpenTofu](https://opentofu.org/)'s [`fmt`](https://opentofu.org/docs/cli/commands/fmt/)) -- [tflint](https://github.com/terraform-linters/tflint) +- `terraform-lint`: built-in linter (using [tflint](https://github.com/terraform-linters/tflint)) ### YAML diff --git a/modules/hooks.nix b/modules/hooks.nix index 95e7df89..f87cda18 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -3344,12 +3344,13 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol entry = "${hooks.terraform-format.package}/bin/terraform-fmt"; files = "\\.tf$"; }; - tflint = + terraform-lint = { - name = "tflint"; + name = "terraform-lint"; description = "A Pluggable Terraform Linter."; - package = tools.tflint; - entry = "${hooks.tflint.package}/bin/tflint"; + package = tools.terraform-lint; + extraPackages = [ pkgs.tflint ]; + entry = "${hooks.terraform-lint.package}/bin/terraform-lint"; files = "\\.tf$"; }; topiary = diff --git a/nix/terraform-lint/default.nix b/nix/terraform-lint/default.nix new file mode 100644 index 00000000..d47a222a --- /dev/null +++ b/nix/terraform-lint/default.nix @@ -0,0 +1,28 @@ +{ + writeShellApplication, + coreutils, + tflint, +}: + +writeShellApplication { + name = "terraform-lint"; + + runtimeInputs = [ + tflint + coreutils + ]; + + text = '' + red='\033[0;31m' + none='\033[0m' + + for arg in "$@"; do + echo -en "$red$arg$none " + if ! tflint --chdir "$(dirname "$arg")" --filter "$(basename "$arg")"; then + fail=true + fi + done + + [[ -v fail ]] && exit 1 + ''; +} diff --git a/nix/tflint/default.nix b/nix/tflint/default.nix deleted file mode 100644 index 861e64e4..00000000 --- a/nix/tflint/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ lib, writeScriptBin, tflint }: - -if lib.versionAtLeast tflint.version "0.45.0" -then - (writeScriptBin "tflint" '' - #!/usr/bin/env bash - ${tflint}/bin/tflint --chdir "$(dirname $1)" --filter "$(basename $1)" - '') -else - tflint diff --git a/nix/tools.nix b/nix/tools.nix index 9bcc89d5..cd9fc35d 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -181,7 +181,7 @@ in hunspell = callPackage ./hunspell { }; purty = callPackage ./purty { purty = nodePackages.purty; }; terraform-fmt = callPackage ./terraform-fmt { }; - tflint = callPackage ./tflint { }; + terraform-lint = callPackage ./terraform-lint { }; dune-build-opam-files = callPackage ./dune-build-opam-files { dune = dune_3; inherit (pkgsBuildBuild) ocaml; }; dune-fmt = callPackage ./dune-fmt { dune = dune_3; inherit (pkgsBuildBuild) ocaml; }; latexindent = tex;