Skip to content

Commit aef7266

Browse files
bfladappilon
authored andcommitted
helper/schema: Support serialization of bool values in TypeMap values
Reference: hashicorp/terraform-provider-aws#13549 This may only be an issue with Terraform 0.11 and earlier with an obscure schema of: ```go "attr": { Type: schema.TypeSet, Optional: true, Elem: &schema.Schema{ Type: schema.TypeMap, Elem: &schema.Schema{ Type: schema.TypeString, }, }, ``` Previously, this would panic (with updated test): ```console $ go test ./helper/schema -run=TestSerializeForHash --- FAIL: TestSerializeForHash (0.00s) panic: unknown value type in TypeMap bool [recovered] panic: unknown value type in TypeMap bool goroutine 5 [running]: testing.tRunner.func1.1(0x1a4a5e0, 0xc0004b9920) /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:940 +0x2f5 testing.tRunner.func1(0xc000372c60) /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:943 +0x3f9 panic(0x1a4a5e0, 0xc0004b9920) /usr/local/Cellar/go/1.14.3/libexec/src/runtime/panic.go:969 +0x166 github.com/hashicorp/terraform-plugin-sdk/helper/schema.SerializeValueForHash(0xc000085bb8, 0x1aaef40, 0xc000528450, 0xc000531400) /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/serialize.go:61 +0x8c9 github.com/hashicorp/terraform-plugin-sdk/helper/schema.TestSerializeForHash(0xc000372c60) /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/serialize_test.go:230 +0x1520 testing.tRunner(0xc000372c60, 0x1c2e848) /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:991 +0xdc created by testing.(*T).Run /usr/local/Cellar/go/1.14.3/libexec/src/testing/testing.go:1042 +0x357 FAIL github.com/hashicorp/terraform-plugin-sdk/helper/schema 5.797s ```
1 parent 838e0bd commit aef7266

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

helper/schema/serialize.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func SerializeValueForHash(buf *bytes.Buffer, val interface{}, schema *Schema) {
5151
buf.WriteRune(':')
5252

5353
switch innerVal := innerVal.(type) {
54+
case bool:
55+
buf.WriteString(strconv.FormatBool(innerVal))
5456
case int:
5557
buf.WriteString(strconv.Itoa(innerVal))
5658
case float64:

helper/schema/serialize_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ func TestSerializeForHash(t *testing.T) {
157157
},
158158
},
159159
Value: map[string]interface{}{
160-
"foo": "bar",
161-
"baz": "foo",
160+
"bool": true,
161+
"float": 1.2,
162+
"int": 1,
163+
"string": "value",
162164
},
163-
Expected: "[baz:foo;foo:bar;];",
165+
Expected: "[bool:true;float:1.2;int:1;string:value;];",
164166
},
165167

166168
{

0 commit comments

Comments
 (0)