Merge pull request #3505 from hashicorp/f-validatefunc-maps
helper/schema: ValidateFunc support for maps
This commit is contained in:
commit
6020d0ab81
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue