-
Notifications
You must be signed in to change notification settings - Fork 58
Description
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 tidyIf 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 ./...