diff --git a/cmd/packer-sdc/README.md b/cmd/packer-sdc/README.md index 5140e950f..381bcd9b4 100644 --- a/cmd/packer-sdc/README.md +++ b/cmd/packer-sdc/README.md @@ -19,3 +19,4 @@ specific help commands: * `packer-sdc plugin-check -h` * `packer-sdc struct-markdown -h` * `packer-sdc renderdocs -h` +* `packer-sdc fix -h` diff --git a/cmd/packer-sdc/internal/fix/README.md b/cmd/packer-sdc/internal/fix/README.md new file mode 100644 index 000000000..a1ecb208e --- /dev/null +++ b/cmd/packer-sdc/internal/fix/README.md @@ -0,0 +1,16 @@ +## `packer-sdc fix` + +Fix rewrites parts of the plugin codebase to address known issues or common workarounds used within plugins consuming the Packer plugin SDK. + +Options: + + -diff If the -diff flag is set, no files are rewritten. Instead, fix prints the differences a rewrite would introduce. + +Available Fixes: + + gocty Adds a replace directive for github.com/zclconf/go-cty to github.com/nywilken/go-cty + + +### Related Issues +Use `packer-sdc fix` to resolve the [cty.Value does not implement gob.GobEncoder](https://github.com/hashicorp/packer-plugin-sdk/issues/187) + diff --git a/cmd/packer-sdc/internal/fix/cmd.go b/cmd/packer-sdc/internal/fix/cmd.go new file mode 100644 index 000000000..d1bc6ef6d --- /dev/null +++ b/cmd/packer-sdc/internal/fix/cmd.go @@ -0,0 +1,158 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package fix + +import ( + "bytes" + "errors" + "flag" + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/pkg/diff" +) + +const cmdPrefix string = "fix" + +// Command is the base entry for the fix sub-command. +type Command struct { + Dir string + Diff bool +} + +// Flags contain the default flags for the fix sub-command. +func (cmd *Command) Flags() *flag.FlagSet { + fs := flag.NewFlagSet(cmdPrefix, flag.ExitOnError) + fs.BoolVar(&cmd.Diff, "diff", false, "if set prints the differences a rewrite would introduce.") + return fs +} + +// Help displays usage for the command. +func (cmd *Command) Help() string { + var s strings.Builder + for _, fix := range availableFixes { + s.WriteString(fmt.Sprintf(" %s\t\t%s\n", fix.name, fix.description)) + } + + helpText := ` +Usage: packer-sdc fix [options] directory + + Fix rewrites parts of the plugin codebase to address known issues or + common workarounds used within plugins consuming the Packer plugin SDK. + +Options: + -diff If the -diff flag is set fix prints the differences an applied fix would introduce. + +Available fixes: +%s` + return fmt.Sprintf(helpText, s.String()) +} + +// Run executes the command +func (cmd *Command) Run(args []string) int { + if err := cmd.run(args); err != nil { + fmt.Printf("%v", err) + return 1 + } + return 0 +} + +func (cmd *Command) run(args []string) error { + f := cmd.Flags() + err := f.Parse(args) + if err != nil { + return errors.New("unable to parse flags for fix command") + } + + if f.NArg() != 1 { + err := fmt.Errorf("packer-sdc fix: missing directory argument\n%s", cmd.Help()) + return err + } + + dir := f.Arg(0) + if dir == "." || dir == "./..." { + dir, _ = os.Getwd() + } + + info, err := os.Stat(dir) + if err != nil && os.IsNotExist(err) { + return errors.New("a plugin root directory must be specified or a dot for the current directory") + } + + if !info.IsDir() { + return errors.New("a plugin root directory must be specified or a dot for the current directory") + } + + dir, err = filepath.Abs(dir) + if err != nil { + return errors.New("unable to determine the absolute path for the provided plugin root directory") + } + cmd.Dir = dir + + return processFiles(cmd.Dir, cmd.Diff) +} + +func (cmd *Command) Synopsis() string { + return "Rewrites parts of the plugin codebase to address known issues or common workarounds within plugins consuming the Packer plugin SDK." +} + +func processFiles(rootDir string, showDiff bool) error { + srcFiles := make(map[string][]byte) + fixedFiles := make(map[string][]byte) + + var hasErrors error + for _, f := range availableFixes { + matches, err := f.scan(rootDir) + if err != nil { + return fmt.Errorf("failed to apply %s fix: %s", f.name, err) + } + + //matches contains all files to apply the said fix on + for _, filename := range matches { + if _, ok := srcFiles[filename]; !ok { + bs, err := os.ReadFile(filename) + if err != nil { + hasErrors = errors.Join(hasErrors, err) + } + srcFiles[filename] = bytes.Clone(bs) + } + + fixedData, ok := fixedFiles[filename] + if !ok { + fixedData = bytes.Clone(srcFiles[filename]) + } + + fixedData, err := f.fix(filename, fixedData) + if err != nil { + hasErrors = errors.Join(hasErrors, err) + continue + } + if bytes.Equal(fixedData, srcFiles[filename]) { + continue + } + fixedFiles[filename] = bytes.Clone(fixedData) + } + } + + if hasErrors != nil { + return hasErrors + } + + if showDiff { + for filename, fixedData := range fixedFiles { + diff.Text(filename, filename+"fixed", string(srcFiles[filename]), string(fixedData), os.Stdout) + } + return nil + } + + for filename, fixedData := range fixedFiles { + fmt.Println(filename) + info, _ := os.Stat(filename) + os.WriteFile(filename, fixedData, info.Mode()) + } + + return nil +} diff --git a/cmd/packer-sdc/internal/fix/fix.go b/cmd/packer-sdc/internal/fix/fix.go new file mode 100644 index 000000000..c1dede85b --- /dev/null +++ b/cmd/packer-sdc/internal/fix/fix.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package fix + +// Fixer applies all defined fixes on a plugin dir; a Fixer should be idempotent. +// The caller of any fix is responsible for checking if the file context have changed. +type fixer interface { + fix(filename string, data []byte) ([]byte, error) +} + +type fix struct { + name, description string + scan func(dir string) ([]string, error) + fixer +} + +var ( + // availableFixes to apply to a plugin - refer to init func + availableFixes []fix +) + +func init() { + availableFixes = []fix{ + goctyFix, + } +} diff --git a/cmd/packer-sdc/internal/fix/gocty.go b/cmd/packer-sdc/internal/fix/gocty.go new file mode 100644 index 000000000..8bd4507a8 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/gocty.go @@ -0,0 +1,114 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package fix + +import ( + "fmt" + "os" + "path" + + "golang.org/x/mod/modfile" +) + +const ( + sdkPath string = "github.com/hashicorp/packer-plugin-sdk" + oldPath string = "github.com/zclconf/go-cty" + newPath string = "github.com/nywilken/go-cty" + newVersion string = "1.12.1" + modFilename string = "go.mod" +) + +var goctyFix = fix{ + name: "gocty", + description: "Adds a replace directive for github.com/zclconf/go-cty to github.com/nywilken/go-cty", + scan: modPaths, + fixer: goCtyFix{ + OldPath: oldPath, + NewPath: newPath, + NewVersion: newVersion, + }, +} + +// modPaths scans the incoming dir for potential go.mod files to fix. +func modPaths(dir string) ([]string, error) { + paths := []string{ + path.Join(dir, modFilename), + } + return paths, nil + +} + +type goCtyFix struct { + OldPath, NewPath, NewVersion string +} + +func (f goCtyFix) modFileFormattedVersion() string { + return fmt.Sprintf("v%s", f.NewVersion) +} + +// Fix applies a replace directive in a projects go.mod file for f.OldPath to f.NewPath. +// This fix applies to the replacement of github.com/zclconf/go-cty, as described in https://github.com/hashicorp/packer-plugin-sdk/issues/187 +// The return data contains the data file with the applied fix. In cases where the fix is already applied or not needed the original data is returned. +func (f goCtyFix) fix(modFilePath string, data []byte) ([]byte, error) { + if _, err := os.Stat(modFilePath); err != nil { + return nil, fmt.Errorf("failed to find go.mod file %s", modFilePath) + } + + mf, err := modfile.Parse(modFilePath, data, nil) + if err != nil { + return nil, fmt.Errorf("%s: failed to parse go.mod file: %v", modFilePath, err) + } + + // fix doesn't apply to go.mod with no module dependencies + if len(mf.Require) == 0 { + return data, nil + } + + var requiresSDK, requiresGoCty bool + for _, req := range mf.Require { + if req.Mod.Path == sdkPath { + requiresSDK = true + } + if req.Mod.Path == f.OldPath { + requiresGoCty = true + } + + if requiresSDK && requiresGoCty { + break + } + } + + if !(requiresSDK && requiresGoCty) { + return data, nil + } + + for _, r := range mf.Replace { + if r.Old.Path != f.OldPath { + continue + } + + if r.New.Path != f.NewPath { + return nil, fmt.Errorf("%s: found unexpected replace for %s", modFilePath, r.Old.Path) + } + + if r.New.Version == f.modFileFormattedVersion() { + return data, nil + } + } + + if err := mf.DropReplace(f.OldPath, ""); err != nil { + return nil, fmt.Errorf("%s: failed to drop previously added replacement fix %v", modFilePath, err) + } + + commentSuffix := " // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187" + if err := mf.AddReplace(f.OldPath, "", f.NewPath, f.modFileFormattedVersion()+commentSuffix); err != nil { + return nil, fmt.Errorf("%s: failed to apply go-cty fix: %v", modFilePath, err) + } + + newData, err := mf.Format() + if err != nil { + return nil, err + } + return newData, nil +} diff --git a/cmd/packer-sdc/internal/fix/gocty_test.go b/cmd/packer-sdc/internal/fix/gocty_test.go new file mode 100644 index 000000000..132898edb --- /dev/null +++ b/cmd/packer-sdc/internal/fix/gocty_test.go @@ -0,0 +1,156 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package fix + +import ( + "os" + "path/filepath" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func copyToTempFile(t testing.TB, data []byte) string { + t.Helper() + dir := t.TempDir() + fn := filepath.Join(dir, "go.mod") + err := os.WriteFile(fn, data, os.ModePerm) + if err != nil { + t.Fatalf("Failed to create test mod file: %s", err) + } + return dir +} + +func goctyTestFixer() goCtyFix { + return goCtyFix{ + OldPath: oldPath, + NewPath: newPath, + NewVersion: newVersion, + } +} + +func TestFixGoCty_FixNotNeeded(t *testing.T) { + tt := []struct { + name string + fixtureDir string + }{ + { + name: "empty mod file", + fixtureDir: filepath.Join("testdata", "empty"), + }, + { + name: "no requires for go-cty or packer-plugin-sdk modules", + fixtureDir: filepath.Join("testdata", "missing-requires", "both"), + }, + { + name: "no go-cty module dependency", + fixtureDir: filepath.Join("testdata", "missing-requires", "go-cty"), + }, + { + name: "no packer-plugin-sdk module dependency", + fixtureDir: filepath.Join("testdata", "missing-requires", "packer-plugin-sdk"), + }, + { + name: "previously fixed mod file", + fixtureDir: filepath.Join("testdata", "fixed", "basic"), + }, + { + name: "fixed mod file with other replace directives", + fixtureDir: filepath.Join("testdata", "fixed", "many-replace"), + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + testFixer := goctyTestFixer() + testFixtureDir := tc.fixtureDir + expectedFn := filepath.Join(testFixtureDir, modFilename) + expected, err := os.ReadFile(expectedFn) + if err != nil { + t.Fatalf("failed while reading text fixture: %s", err) + } + + outFileDir := copyToTempFile(t, expected) + outFileFn := filepath.Join(outFileDir, "go.mod") + fixed, err := testFixer.fix(outFileFn, expected) + if err != nil { + t.Fatalf("expected fix to not err but it did: %v", err) + } + + if diff := cmp.Diff(expected, fixed); diff != "" { + t.Errorf("expected no differences but got %q", diff) + } + + }) + } +} + +func TestFixGoCty_Unfixed(t *testing.T) { + tt := []struct { + name string + versionStr string + fixtureDir string + }{ + { + name: "basic unfixed mod file", + fixtureDir: filepath.Join("testdata", "unfixed", "basic"), + }, + { + name: "unfixed mod file with other replace directives", + fixtureDir: filepath.Join("testdata", "unfixed", "many-replace"), + }, + { + name: "out of date fix", + versionStr: "1.13.1", + fixtureDir: filepath.Join("testdata", "unfixed", "version"), + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + testFixer := goctyTestFixer() + if tc.versionStr != "" { + testFixer.NewVersion = tc.versionStr + } + testFixtureDir := tc.fixtureDir + unfixedFn := filepath.Join(testFixtureDir, "go.mod") + unfixed, err := os.ReadFile(unfixedFn) + if err != nil { + t.Fatalf("failed while reading text fixture: %s", err) + } + + outFileDir := copyToTempFile(t, unfixed) + outFileFn := filepath.Join(outFileDir, modFilename) + fixed, err := testFixer.fix(outFileFn, unfixed) + if err != nil { + t.Fatalf("expected fix to not err but it did: %v", err) + } + + expectedFn := filepath.Join(testFixtureDir, "fixed.go.mod") + expected, err := os.ReadFile(expectedFn) + if err != nil { + t.Fatalf("failed while reading text fixture: %s", err) + } + + if diff := cmp.Diff(expected, fixed); diff != "" { + t.Errorf("expected differences but got %q", diff) + } + + }) + } +} + +func TestFixGoCty_InvalidReplacePath(t *testing.T) { + testFixer := goctyTestFixer() + testFixtureDir := filepath.Join("testdata", "invalid") + expectedFn := filepath.Join(testFixtureDir, modFilename) + expected, err := os.ReadFile(expectedFn) + if err != nil { + t.Fatalf("failed while reading text fixture: %s", err) + } + + outFileDir := copyToTempFile(t, expected) + outFileFn := filepath.Join(outFileDir, modFilename) + if _, err := testFixer.fix(outFileFn, expected); err == nil { + t.Fatalf("expected fix to err but it didn't: %v", err) + } +} diff --git a/cmd/packer-sdc/internal/fix/testdata/empty/go.mod b/cmd/packer-sdc/internal/fix/testdata/empty/go.mod new file mode 100644 index 000000000..c364a0d1b --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/empty/go.mod @@ -0,0 +1,3 @@ +module github.com/hashicorp/example + +go 1.20 diff --git a/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.mod b/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.mod new file mode 100644 index 000000000..4247f0444 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/fixed/basic/go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.17 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.12.1 diff --git a/cmd/packer-sdc/internal/fix/testdata/fixed/many-replace/go.mod b/cmd/packer-sdc/internal/fix/testdata/fixed/many-replace/go.mod new file mode 100644 index 000000000..b011417ab --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/fixed/many-replace/go.mod @@ -0,0 +1,13 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/hashicorp/packer-plugin-sdk => github.com/example/packer-plugin-sdk v0.5.0 + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.12.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187 diff --git a/cmd/packer-sdc/internal/fix/testdata/invalid/go.mod b/cmd/packer-sdc/internal/fix/testdata/invalid/go.mod new file mode 100644 index 000000000..bec402a4e --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/invalid/go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/zclconf/go-cty => github.com/random/go-cty v1.14.1 diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.mod b/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.mod new file mode 100644 index 000000000..966657efd --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/both/go.mod @@ -0,0 +1,18 @@ +module example + +require ( + github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d + github.com/google/go-cmp v0.3.0 + github.com/hashicorp/go-cleanhttp v0.5.0 + github.com/hashicorp/go-multierror v1.1.0 + github.com/hashicorp/go-safetemp v1.0.0 + github.com/hashicorp/go-version v1.1.0 + github.com/klauspost/compress v1.11.2 + github.com/mitchellh/go-homedir v1.0.0 + github.com/mitchellh/go-testing-interface v1.0.0 + github.com/ulikunitz/xz v0.5.8 +) + +require github.com/hashicorp/errwrap v1.0.0 // indirect + +go 1.18 diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod new file mode 100644 index 000000000..ad38b4bd0 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/go-cty/go.mod @@ -0,0 +1,19 @@ +module example + +require ( + github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d + github.com/google/go-cmp v0.3.0 + github.com/hashicorp/go-cleanhttp v0.5.0 + github.com/hashicorp/go-multierror v1.1.0 + github.com/hashicorp/go-safetemp v1.0.0 + github.com/hashicorp/go-version v1.1.0 + github.com/hashicorp/packer-plugin-sdk v0.4.0 + github.com/klauspost/compress v1.11.2 + github.com/mitchellh/go-homedir v1.0.0 + github.com/mitchellh/go-testing-interface v1.0.0 + github.com/ulikunitz/xz v0.5.8 +) + +require github.com/hashicorp/errwrap v1.0.0 // indirect + +go 1.18 diff --git a/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod new file mode 100644 index 000000000..aace57136 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/missing-requires/packer-plugin-sdk/go.mod @@ -0,0 +1,19 @@ +module example + +require ( + github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d + github.com/google/go-cmp v0.3.0 + github.com/hashicorp/go-cleanhttp v0.5.0 + github.com/hashicorp/go-multierror v1.1.0 + github.com/hashicorp/go-safetemp v1.0.0 + github.com/hashicorp/go-version v1.1.0 + github.com/klauspost/compress v1.11.2 + github.com/mitchellh/go-homedir v1.0.0 + github.com/mitchellh/go-testing-interface v1.0.0 + github.com/ulikunitz/xz v0.5.8 + github.com/zclconf/go-cty v1.13.1 +) + +require github.com/hashicorp/errwrap v1.0.0 // indirect + +go 1.18 diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/fixed.go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/fixed.go.mod new file mode 100644 index 000000000..da456395d --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/fixed.go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.12.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187 diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.mod new file mode 100644 index 000000000..8a509b792 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/basic/go.mod @@ -0,0 +1,9 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/fixed.go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/fixed.go.mod new file mode 100644 index 000000000..b011417ab --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/fixed.go.mod @@ -0,0 +1,13 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/hashicorp/packer-plugin-sdk => github.com/example/packer-plugin-sdk v0.5.0 + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.12.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187 diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/go.mod new file mode 100644 index 000000000..10c40e72a --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/many-replace/go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/hashicorp/packer-plugin-sdk => github.com/example/packer-plugin-sdk v0.5.0 diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/version/fixed.go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/fixed.go.mod new file mode 100644 index 000000000..90da23380 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/fixed.go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.13.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187 diff --git a/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.mod b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.mod new file mode 100644 index 000000000..90da23380 --- /dev/null +++ b/cmd/packer-sdc/internal/fix/testdata/unfixed/version/go.mod @@ -0,0 +1,11 @@ +module packer-plugin-scaffolding + +go 1.20 + +require ( + github.com/hashicorp/hcl/v2 v2.13.0 + github.com/hashicorp/packer-plugin-sdk v0.3.1 + github.com/zclconf/go-cty v1.10.0 +) + +replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.13.1 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187 diff --git a/cmd/packer-sdc/main.go b/cmd/packer-sdc/main.go index a5e6b7f03..5855a3b25 100644 --- a/cmd/packer-sdc/main.go +++ b/cmd/packer-sdc/main.go @@ -8,6 +8,7 @@ import ( "log" "os" + "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/fix" mapstructure_to_hcl2 "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/mapstructure-to-hcl2" "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/plugincheck" "github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc/internal/renderdocs" @@ -44,6 +45,9 @@ func main() { "plugin-check": func() (cli.Command, error) { return &plugincheck.Command{}, nil }, + "fix": func() (cli.Command, error) { + return &fix.Command{}, nil + }, } exitStatus, err := c.Run() diff --git a/go.mod b/go.mod index d42f13c9a..c5c590c63 100644 --- a/go.mod +++ b/go.mod @@ -58,6 +58,7 @@ require ( github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db github.com/pierrec/lz4 v2.6.1+incompatible // indirect + github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e github.com/pkg/errors v0.9.1 github.com/pkg/sftp v1.13.2 github.com/ryanuber/go-glob v1.0.0 diff --git a/go.sum b/go.sum index 1b95da008..1a8fe2887 100644 --- a/go.sum +++ b/go.sum @@ -374,6 +374,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=