Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cty.Value does not implement gob.GobEncoder #187

Open
nywilken opened this issue Jun 14, 2023 · 3 comments · Fixed by exoscale/packer-plugin-exoscale#44
Open

cty.Value does not implement gob.GobEncoder #187

nywilken opened this issue Jun 14, 2023 · 3 comments · Fixed by exoscale/packer-plugin-exoscale#44
Labels
bug Something isn't working dependencies Pull requests that update a dependency file version/bump minor A PR that changes behavior or contains breaking changes template configuration options.
Milestone

Comments

@nywilken
Copy link
Contributor

nywilken commented Jun 14, 2023

Related Errors

  • cannot use cty.Value{} (value of type cty.Value) as gob.GobEncoder value in variable declaration
  • Datasource.OutputSpec failed: gob: type cty.Type has no exported fields

What's this Error?

~> go get github.com/hashicorp/go-cty v1.13.0
~> make dev
packer-plugin-sdk/rpc/init.go:20:24: cannot use cty.Value{} (value of type cty.Value) 
as gob.GobEncoder value in variable declaration: cty.Value does not implement gob.GobEncoder 
(missing method GobEncode)

In v1.11.0, the github.com/zclconf/go-cty package dropped support for encoding/gob. Gob support is used by the Packer SDK to serialize HCL2 object specs over the wire. If a plugin or Packer upgrades their version of github.com/zclconf/go-cty to one that does not contain Gob support (v1.11.0+) the plugin will build but crash when trying to run a build on an HCL2 template.

The error being reported above is due to a compile type check added to the Packer SDK to alert a consumer of the SDK that they are using an unsupported version of github.com/zclconf/go-cty. The gob.GobEncodercheck was added as a guard to prevent Packer SDK consumers from becoming out of sync with unsupported go-cty versions.

How to fix this Error #

If you are seeing this error then you are running a release of the Packer plugin SDK that now enforces a type check for the encoding/gob support in github.com/zclconf/go-cty. There are a number of ways to fix this issue, which are all meant to be temporary fixes until v1.0.0 of the Packer Plugin SDK, which will move from using encoding/gob for serializing cty Values.

In an effort to provide Packer plugins access to the github.com/zclconf/go-cty enhancements, while still providing access to encoding/gob support the Packer team has forked the go-cty package under github.com/nywilken/go-cty. This is a temporary fork that will be removed once it is no longer needed. Until then plugin developers are encourage to use the fork as a replacement (within the go.mod file) for github.com/zclconf/go-cty.

For a complete list of changes within the go-cty fork for Packer refer to the CHANGELOG

If you are using a version of the Packer Plugin SDK prior to the release of the compile time check within the SDK you can simply use the recommended replace directive (Option 1) to pull in the fork and gain access to the latest enhancements to go-cty.

Option 1: Run packer-sdc fix Command

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.

go get github.com/hashicorp/[email protected]
go install github.com/hashicorp/packer-plugin-sdk/cmd/[email protected]
packer-sdc fix .
go mod tidy

If no replace directive is found it will be automatically added to the go.mod file, which you can then run go mod tidy and go test ./... -v against your plugin to verify the fix has been applied.

In the future release running packer-sdc fix will update versions of the fork, and when the time comes remove it from the mod file.

Option 2: Manual Replace Directive

Add a replace directive to the go.mod file within your plugin's project root directory.
Please check the fork CHANGELOG and tags for the latest tagged release.

go get github.com/hashicorp/[email protected] &&\
go mod edit -replace "github.com/zclconf/go-cty=github.com/nywilken/[email protected]" &&\
go mod tidy &&\
go test ./...
@nywilken nywilken added bug Something isn't working dependencies Pull requests that update a dependency file version/bump minor A PR that changes behavior or contains breaking changes template configuration options. labels Jun 14, 2023
@nywilken nywilken added this to the 0.5.0 milestone Jun 14, 2023
@nywilken nywilken pinned this issue Jun 16, 2023
nywilken pushed a commit that referenced this issue Jun 20, 2023
…/go-cty

In an effort to provide Packer plugins access to the github.com/zclconf/go-cty enhancements,
while still providing access to encoding/gob support the Packer team has forked the go-cty package under github.com/nywilken/go-cty.
This is a temporary fork that will be removed once it is no longer needed.

Refer to #187
nywilken pushed a commit that referenced this issue Jul 5, 2023
…/go-cty

In an effort to provide Packer plugins access to the github.com/zclconf/go-cty enhancements,
while still providing access to encoding/gob support the Packer team has forked the go-cty package under github.com/nywilken/go-cty.
This is a temporary fork that will be removed once it is no longer needed.

Refer to #187
@Prateeknandle
Copy link

After following option - 1 I'm getting error while running go test ./...

$ go test ./...                                             ✹main 
# github.com/hashicorp/hcl/v2/hcldec
../../../pkg/mod/github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:1627:19: undefined: cty.RefinementBuilder
../../../pkg/mod/github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:1643:20: wrappedVal.RefineWith undefined (type cty.Value has no field or method RefineWith)

go.mod :
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

packer-plugin-sdk v0.5.1 in go.mod

is this also an issue, anybody faced it, how to resolve it

@Prateeknandle
Copy link

FYI : replace github.com/hashicorp/hcl/v2 => github.com/hashicorp/hcl/v2 v2.16.2 this worked

@nywilken
Copy link
Contributor Author

After following option - 1 I'm getting error while running go test ./...

$ go test ./...                                             ✹main 
# github.com/hashicorp/hcl/v2/hcldec
../../../pkg/mod/github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:1627:19: undefined: cty.RefinementBuilder
../../../pkg/mod/github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:1643:20: wrappedVal.RefineWith undefined (type cty.Value has no field or method RefineWith)

go.mod : 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

packer-plugin-sdk v0.5.1 in go.mod

is this also an issue, anybody faced it, how to resolve it

@Prateeknandle thanks again for bubbling this up. As you found version of hcl/v2 2.17.0+ required a newer version of the github.com/zclconf/go-cty. This issue has been addressed in the latest Packer Plugin SDK release v0.5.2, where the go-cty fork now contains all the changes from zclconf/[email protected].

To update your plugin pull down the latest version of the Packer plugin SDK and re-apply the GoCty fix.

go get github.com/hashicorp/[email protected]
go install github.com/hashicorp/packer-plugin-sdk/cmd/[email protected]
packer-sdc fix .
go mod tidy

breed808 added a commit to breed808/packer-plugin-tss that referenced this issue Dec 4, 2023
Manual intervention required to update:

* github.com/hashicorp/hcl/v2
* github.com/hashicorp/packer-plugin-sdk
* github.com/zclconf/go-cty

See hashicorp/packer-plugin-sdk#187 for
further context.
dbast added a commit to mkaczanowski/packer-builder-arm that referenced this issue Dec 23, 2023
dbast added a commit to mkaczanowski/packer-builder-arm that referenced this issue Dec 23, 2023
* Bump github.com/hashicorp/packer-plugin-sdk from 0.5.1 to 0.5.2

Bumps [github.com/hashicorp/packer-plugin-sdk](https://github.com/hashicorp/packer-plugin-sdk) from 0.5.1 to 0.5.2.
- [Release notes](https://github.com/hashicorp/packer-plugin-sdk/releases)
- [Changelog](https://github.com/hashicorp/packer-plugin-sdk/blob/main/CHANGELOG.md)
- [Commits](hashicorp/packer-plugin-sdk@v0.5.1...v0.5.2)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/packer-plugin-sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Apply `packer-sdc fix .`

See also hashicorp/packer-plugin-sdk#187 (comment)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel Bast <[email protected]>
shurkys pushed a commit to shurkys/packer-plugin-opennebula that referenced this issue May 14, 2024
bryborge added a commit to bryborge/packer-plugin-demo-pkr-plgin that referenced this issue Jan 1, 2025
kobajagi added a commit to exoscale/packer-plugin-exoscale that referenced this issue Jan 13, 2025
This PR fixes the issue with `user_data` and `user_data_file` builder
config parameters. As the config spec was not updated they were causing
config validation errors.

Following procedure was applied:

- Go version was bumped to 1.23;
- SDK version bumped to 0.54.0;
- `packer-sdc fix .` applied (fixes [packer SDK
bug](hashicorp/packer-plugin-sdk#187));
- config spec updated;
- replaced deprecated `version.InitializePluginVersion` (fixes
`staticcheck` complaint).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file version/bump minor A PR that changes behavior or contains breaking changes template configuration options.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants