fix(depotfmt): handle multiple terraform files

`terraform fmt` can only handle a single path, but treefmt expects
formatters to be able to handle multiple paths at once.

this wraps it in a small shell script that calls `terraform fmt` with
at most one path at a time.

Change-Id: I2b9c1b89b5a276f3d4915b95608ce36b2509e334
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4639
Tested-by: BuildkiteCI
Autosubmit: tazjin <mail@tazj.in>
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2021-12-26 19:06:56 +03:00 committed by clbot
parent c1d7714a21
commit 8a5ccd7089

View file

@ -3,6 +3,12 @@
{ depot, pkgs, ... }: { depot, pkgs, ... }:
let let
# terraform fmt can't handle multiple paths at once, but treefmt
# expects this
terraformat = pkgs.writeShellScript "terraformat" ''
echo "$@" | xargs -n1 ${pkgs.terraform}/bin/terraform fmt
'';
config = pkgs.writeText "depot-treefmt-config" '' config = pkgs.writeText "depot-treefmt-config" ''
[formatter.go] [formatter.go]
command = "${pkgs.go}/bin/gofmt" command = "${pkgs.go}/bin/gofmt"
@ -10,8 +16,7 @@ let
includes = ["*.go"] includes = ["*.go"]
[formatter.tf] [formatter.tf]
command = "${pkgs.terraform}/bin/terraform" command = "${terraformat}"
options = [ "fmt" ]
includes = [ "*.tf" ] includes = [ "*.tf" ]
''; '';