From 05a1a6f4761eaeca25bd116fe661db29f16c62b1 Mon Sep 17 00:00:00 2001 From: Mustafa Babil Date: Thu, 17 Jun 2021 16:50:34 +0200 Subject: [PATCH] added recursive flag to fmt --- DOCS.md | 4 ++++ plugin.go | 4 ++++ plugin_test.go | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index 41e9f58..3f3ff92 100644 --- a/DOCS.md +++ b/DOCS.md @@ -194,6 +194,7 @@ pipeline: + write: false + diff: true + check: true ++ recursive: true ``` You may want to run some executions in parallel without having racing condition problems with the .terraform dir and @@ -244,6 +245,9 @@ fmt_options.diff fmt_options.check : Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise. Default `false`. +fmt_options.recursive +: Process files in subdirectories as well. Default `false`. + vars : a map of variables to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `-var =` option. diff --git a/plugin.go b/plugin.go index e89e373..59263df 100644 --- a/plugin.go +++ b/plugin.go @@ -57,6 +57,7 @@ type ( Write *bool `json:"write"` Diff *bool `json:"diff"` Check *bool `json:"check"` + Recursive *bool `json:"recursive"` } // Plugin represents the plugin instance to be executed @@ -364,6 +365,9 @@ func tfFmt(config Config) *exec.Cmd { if config.FmtOptions.Check != nil { args = append(args, fmt.Sprintf("-check=%t", *config.FmtOptions.Check)) } + if config.FmtOptions.Recursive != nil { + args = append(args, fmt.Sprintf("-recursive=%t", *config.FmtOptions.Recursive)) + } return exec.Command( "terraform", args..., diff --git a/plugin_test.go b/plugin_test.go index bce7901..c5c1bb0 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -243,6 +243,11 @@ func TestPlugin(t *testing.T) { args{config: Config{FmtOptions: FmtOptions{Check: &affirmative}}}, exec.Command("terraform", "fmt", "-check=true"), }, + { + "with recursive", + args{config: Config{FmtOptions: FmtOptions{Recursive: &affirmative}}}, + exec.Command("terraform", "fmt", "-recursive=true"), + }, { "with combination", args{config: Config{FmtOptions: FmtOptions{ @@ -250,8 +255,9 @@ func TestPlugin(t *testing.T) { Write: &negative, Diff: &affirmative, Check: &affirmative, + Recursive: &affirmative, }}}, - exec.Command("terraform", "fmt", "-list=false", "-write=false", "-diff=true", "-check=true"), + exec.Command("terraform", "fmt", "-list=false", "-write=false", "-diff=true", "-check=true", "-recursive=true"), }, }