diff --git a/cmd/mapstructure-to-hcl2/mapstructure-to-hcl2.go b/cmd/mapstructure-to-hcl2/mapstructure-to-hcl2.go index 54359cbe5..3721129e8 100644 --- a/cmd/mapstructure-to-hcl2/mapstructure-to-hcl2.go +++ b/cmd/mapstructure-to-hcl2/mapstructure-to-hcl2.go @@ -25,7 +25,6 @@ import ( "bytes" "flag" "fmt" - "go/format" "go/types" "io" "log" @@ -39,6 +38,7 @@ import ( "github.com/zclconf/go-cty/cty" "golang.org/x/tools/go/packages" + "golang.org/x/tools/imports" ) var ( @@ -189,7 +189,7 @@ func main() { log.Fatalf("os.Create: %v", err) } - _, err = outputFile.Write(goFmt(out.Bytes())) + _, err = outputFile.Write(goFmt(outputFile.Name(), out.Bytes())) if err != nil { log.Fatalf("failed to write file: %v", err) } @@ -575,8 +575,8 @@ func ToSnakeCase(str string) string { return strings.ToLower(snake) } -func goFmt(b []byte) []byte { - fb, err := format.Source(b) +func goFmt(filename string, b []byte) []byte { + fb, err := imports.Process(filename, b, nil) if err != nil { log.Printf("formatting err: %v", err) return b diff --git a/packer/builder_mock.hcl2spec.go b/packer/builder_mock.hcl2spec.go index a406ef9f0..a5ea27c82 100644 --- a/packer/builder_mock.hcl2spec.go +++ b/packer/builder_mock.hcl2spec.go @@ -2,9 +2,10 @@ package packer import ( + "io" + "github.com/hashicorp/hcl/v2/hcldec" "github.com/zclconf/go-cty/cty" - "io" ) // FlatMockBuilder is an auto-generated flat version of MockBuilder.