From f640dd9c9dfb61520ce3141c4bc2f27a30717b68 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 6 May 2021 22:44:28 +0200 Subject: [PATCH] terraform fmt workaround See #97 --- README.md | 1 + devshell.toml | 7 ++++++- docs/formatters.md | 5 +++++ examples/terraform/main.tf | 4 ++++ examples/terraform/two.tf | 4 ++++ scripts/terraform-fmt | 6 ++++++ treefmt.toml | 4 ++++ 7 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 examples/terraform/main.tf create mode 100644 examples/terraform/two.tf create mode 100755 scripts/terraform-fmt diff --git a/README.md b/README.md index cbc6c73..ad7193b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ quite tricky. ## Usage `$ cargo run -- --help` + ``` treefmt 0.1.1 ✨ format all your language! diff --git a/devshell.toml b/devshell.toml index ee4aef9..a313033 100644 --- a/devshell.toml +++ b/devshell.toml @@ -16,12 +16,17 @@ packages = [ # Code formatters "elmPackages.elm-format", "go", - "haskellPackages.ormolu", "haskellPackages.cabal-fmt", + "haskellPackages.ormolu", "nixpkgs-fmt", "nodePackages.prettier", "python3.pkgs.black", "shfmt", + "terraform", "mdbook" ] + +[[env]] +name = "PATH" +eval = "$PWD/target/debug:$PATH" diff --git a/docs/formatters.md b/docs/formatters.md index 91f73d1..ad510ba 100644 --- a/docs/formatters.md +++ b/docs/formatters.md @@ -125,3 +125,8 @@ options = [ ] includes = ["*.sh"] ``` + +## terraform + +terraform fmt only supports formatting one file at the time. See +https://github.com/hashicorp/terraform/pull/28191 diff --git a/examples/terraform/main.tf b/examples/terraform/main.tf new file mode 100644 index 0000000..799e8de --- /dev/null +++ b/examples/terraform/main.tf @@ -0,0 +1,4 @@ + +resource "my_resource" "xxx" { + option = [1, 2, 3] +} diff --git a/examples/terraform/two.tf b/examples/terraform/two.tf new file mode 100644 index 0000000..d111967 --- /dev/null +++ b/examples/terraform/two.tf @@ -0,0 +1,4 @@ + +resource "other_resource" "xxx" { + xxx = "xxx" +} diff --git a/scripts/terraform-fmt b/scripts/terraform-fmt new file mode 100755 index 0000000..5d33466 --- /dev/null +++ b/scripts/terraform-fmt @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euo pipefail + +for path in "$@"; do + terraform fmt "$path" +done diff --git a/treefmt.toml b/treefmt.toml index 027e26e..ea2badb 100644 --- a/treefmt.toml +++ b/treefmt.toml @@ -63,3 +63,7 @@ options = [ "-w", # write back to the file ] includes = ["*.sh"] + +[formatter.terraform] +command = "./scripts/terraform-fmt" +includes = ["*.tf"]