helper/schema: use reflection to verify list

This commit is contained in:
Mitchell Hashimoto 2014-08-18 14:20:57 -07:00
parent 4c9271160e
commit 17d29f7949
1 changed files with 12 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package schema
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -372,10 +373,18 @@ func (m schemaMap) validateList(
raw interface{}, raw interface{},
schema *Schema, schema *Schema,
c *terraform.ResourceConfig) ([]string, []error) { c *terraform.ResourceConfig) ([]string, []error) {
raws, ok := raw.([]interface{}) // We use reflection to verify the slice because you can't
if !ok { // case to []interface{} unless the slice is exactly that type.
rawV := reflect.ValueOf(raw)
if rawV.Kind() != reflect.Slice {
return nil, []error{fmt.Errorf( return nil, []error{fmt.Errorf(
"%s: should be list", k)} "%s: should be a list", k)}
}
// Now build the []interface{}
raws := make([]interface{}, rawV.Len())
for i, _ := range raws {
raws[i] = rawV.Index(i).Interface()
} }
var ws []string var ws []string