Skip to content

Commit

Permalink
Add compile time check for go-cty
Browse files Browse the repository at this point in the history
In v1.11.0, the go-cty package dropped support for encoding/gob. Gob support is used
by the SDK to serialize HCL2 object specs over the wire. If a plugin or Packer upgrades
their version of zclconf/go-cty to one that does not contain Gob support the plugin will build
but crash when trying to run a build on an HCL2 template. By adding this check, a consumer of the SDK
will fail to compile if they are using an unsupported version of go-cty. This check is being added
as a guard to prevent Packer SDK consumers from becoming out of sync with unsupported go-cty versions.

```
~> go get github.com/hashicorp/go-cty v1.13.0
~> make dev
rpc/cty_encode.go:15:24 cannot use cty.Value{} (value of type cty.Value) as type gob.GobEncoder
```
  • Loading branch information
Wilken Rivera authored and nywilken committed Jun 15, 2023
1 parent 7c81952 commit 0c09c89
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rpc/cty_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
package rpc

import (
"encoding/gob"

"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/json"
)

// Test that cty types implement the gob.GobEncoder interface.
// Support for encoding/gob was removed in github.com/zclconf/[email protected].
var _ gob.GobEncoder = cty.Value{}

// cty.Value is does not know how to encode itself through the wire so we
// transform it to bytes.
func encodeCTYValues(config []interface{}) ([]interface{}, error) {
Expand Down

0 comments on commit 0c09c89

Please sign in to comment.