Skip to content

Commit 9811737

Browse files
dantefromhellblaggacao
authored andcommitted
fix: Improve readability of terraform errors
When terraform errors output the affected line-of-code the output is highly unreadable as `config.tf.json' is a one-line JSON file. Since there seems to be no nix expression for pretty printing JSON, this PR uses `jq` on the command line instead. The result is that terraform syntax errors output the single affected line-of-code.
1 parent 403fd2a commit 9811737

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/std/fwlib/blockTypes/terra.nix

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ in
7474
MESSAGE
7575
7676
if [[ -e "$dir/config.tf.json" ]]; then rm -f "$dir/config.tf.json"; fi
77-
cp ${terraformConfiguration} "$dir/config.tf.json"
77+
jq '.' ${terraformConfiguration} > "$dir/config.tf.json"
7878
'';
7979

8080
wrap = cmd: ''
@@ -87,11 +87,11 @@ in
8787
terraform ${cmd} "$@";
8888
'';
8989
in [
90-
(mkCommand currentSystem "init" "tf init" [pkgs.terraform pkgs.terraform-backend-git] (wrap "init") {})
91-
(mkCommand currentSystem "plan" "tf plan" [pkgs.terraform pkgs.terraform-backend-git] (wrap "plan") {})
92-
(mkCommand currentSystem "apply" "tf apply" [pkgs.terraform pkgs.terraform-backend-git] (wrap "apply") {})
93-
(mkCommand currentSystem "state" "tf state" [pkgs.terraform pkgs.terraform-backend-git] (wrap "state") {})
94-
(mkCommand currentSystem "refresh" "tf refresh" [pkgs.terraform pkgs.terraform-backend-git] (wrap "refresh") {})
95-
(mkCommand currentSystem "destroy" "tf destroy" [pkgs.terraform pkgs.terraform-backend-git] (wrap "destroy") {})
90+
(mkCommand currentSystem "init" "tf init" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "init") {})
91+
(mkCommand currentSystem "plan" "tf plan" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "plan") {})
92+
(mkCommand currentSystem "apply" "tf apply" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "apply") {})
93+
(mkCommand currentSystem "state" "tf state" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "state") {})
94+
(mkCommand currentSystem "refresh" "tf refresh" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "refresh") {})
95+
(mkCommand currentSystem "destroy" "tf destroy" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "destroy") {})
9696
];
9797
}

0 commit comments

Comments
 (0)