Merge pull request #3505 from hashicorp/f-validatefunc-maps

helper/schema: ValidateFunc support for maps
This commit is contained in:
Paul Hinze 2015-10-14 15:19:37 -05:00
commit 6020d0ab81
2 changed files with 14 additions and 3 deletions

View File

@ -540,8 +540,8 @@ func (m schemaMap) InternalValidate(topSchemaMap schemaMap) error {
if v.ValidateFunc != nil {
switch v.Type {
case TypeList, TypeSet, TypeMap:
return fmt.Errorf("ValidateFunc is only supported on primitives.")
case TypeList, TypeSet:
return fmt.Errorf("ValidateFunc is not yet supported on lists or sets.")
}
}
}
@ -1118,6 +1118,17 @@ func (m schemaMap) validateMap(
}
}
if schema.ValidateFunc != nil {
validatableMap := make(map[string]interface{})
for _, raw := range raws {
for k, v := range raw.(map[string]interface{}) {
validatableMap[k] = v
}
}
return schema.ValidateFunc(validatableMap, k)
}
return nil, nil
}

View File

@ -2903,7 +2903,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
{
map[string]*Schema{
"foo": &Schema{
Type: TypeMap,
Type: TypeSet,
Required: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
return