diff --git a/command/fmt_test.go b/command/fmt_test.go index b63ca5fb9..0a9c0a6e7 100644 --- a/command/fmt_test.go +++ b/command/fmt_test.go @@ -156,6 +156,7 @@ func Test_fmt_pipe(t *testing.T) { expected string }{ {unformattedHCL, []string{"fmt", "-"}, nil, formattedHCL}, + {formattedHCL, []string{"fmt", "-"}, nil, formattedHCL}, } for _, tc := range tc { diff --git a/hcl2template/formatter.go b/hcl2template/formatter.go index 34d63e8de..700e0c40b 100644 --- a/hcl2template/formatter.go +++ b/hcl2template/formatter.go @@ -139,6 +139,10 @@ func (f *HCL2Formatter) processFile(filename string) ([]byte, error) { outSrc := hclwrite.Format(inSrc) if bytes.Equal(inSrc, outSrc) { + if filename == "-" { + _, _ = f.Output.Write(outSrc) + } + return nil, nil }