hashicorp / packer-plugin-sdk

Packer Plugin SDK enables building Packer plugins (builders, provisioners, or post-processors) to manage any service providers or custom in-house solutions
Mozilla Public License 2.0
34 stars 46 forks source link

[HPR-1190] Add `packer-sdc fix` command #190

Closed nywilken closed 1 year ago

nywilken commented 1 year ago

In an effort to automate the temporary fix, and its removal in the future, a fix sub-command has been added to the packer-sdc command; not to be confused with packer fix which fixes legacy JSON template files.

By running the packer-sdc fix command within the plugin's root project directory the command will check the plugin's go.mod file has a replace directive to the go-cty fork. If no replace directive is found it will be automatically added to the go.mod file.

Depends on #189 Relates to: #187 Closes #135

Example Outputs

Help Output

~>  ./packer-sdc fix -h

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:
  gocty         Adds a replace directive for github.com/zclconf/go-cty to github.com/nywilken/go-cty

Basic Diff

~>  ./packer-sdc fix -diff ../../../packer/
--- /home/vagrant/Development/packer/go.mod
+++ /home/vagrant/Development/packer/go.modfixed
@@ -213,3 +213,5 @@
 )

 go 1.20
+
+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

Applied Fix


~>  ./packer-sdc fix ../../../packer/
/home/vagrant/Development/packer/go.mod
~>  git diff
diff --git a/go.mod b/go.mod
index fa48d7d58..02b455992 100644
--- a/go.mod
+++ b/go.mod
@@ -213,3 +213,5 @@ require (
 )

 go 1.20
+
+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