From 2b50d44aa46985a65ece6947896456d2e8fd2d2d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 17 Oct 2014 23:23:50 -0700 Subject: [PATCH] helper/schema: validate Set is a set type [GH-413] --- CHANGELOG.md | 1 + helper/schema/schema.go | 2 ++ helper/schema/schema_test.go | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2015e095..24402be8a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ BUG FIXES: computed so the value is still unknown. * core: If a resource fails to create and has provisioners, it is marked as tainted. [GH-434] + * core: Set types are validated to be sets. [GH-413] * providers/aws: Refresh of launch configs and autoscale groups load the correct data and don't incorrectly recreate themselves. [GH-425] * providers/aws: Fix case where ELB would incorrectly plan to modify diff --git a/helper/schema/schema.go b/helper/schema/schema.go index d074e95127..3650123d36 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -819,6 +819,8 @@ func (m schemaMap) validatePrimitive( } switch schema.Type { + case TypeSet: + fallthrough case TypeList: return m.validateList(k, raw, schema, c) case TypeInt: diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 66830869c1..8a06d2c487 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -1970,6 +1970,26 @@ func TestSchemaMap_Validate(t *testing.T) { Err: true, }, + + // Not a set + { + Schema: map[string]*Schema{ + "ports": &Schema{ + Type: TypeSet, + Required: true, + Elem: &Schema{Type: TypeInt}, + Set: func(a interface{}) int { + return a.(int) + }, + }, + }, + + Config: map[string]interface{}{ + "ports": "foo", + }, + + Err: true, + }, } for i, tc := range cases {