Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <key>=<value>` option.
Expand Down
4 changes: 4 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -354,6 +355,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...,
Expand Down
8 changes: 7 additions & 1 deletion plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,21 @@ 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{
List: &negative,
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"),
},
}

Expand Down