Merge pull request #13046 from hashicorp/jbardin/GH-12892

reify the list values before validation
This commit is contained in:
James Bardin 2017-03-24 12:13:49 -04:00 committed by GitHub
commit 399715e1b7
2 changed files with 49 additions and 0 deletions

View File

@ -1219,6 +1219,13 @@ func (m schemaMap) validateList(
for i, raw := range raws {
key := fmt.Sprintf("%s.%d", k, i)
// Reify the key value from the ResourceConfig.
// If the list was computed we have all raw values, but some of these
// may be known in the config, and aren't individually marked as Computed.
if r, ok := c.Get(key); ok {
raw = r
}
var ws2 []string
var es2 []error
switch t := schema.Elem.(type) {

View File

@ -7,6 +7,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"testing"
"github.com/hashicorp/hil"
@ -4924,6 +4925,47 @@ func TestSchemaMap_Validate(t *testing.T) {
},
Err: true,
},
// The Validation function should not see interpolation strings from
// non-computed values.
"set with partially computed list and map": {
Schema: map[string]*Schema{
"outer": &Schema{
Type: TypeSet,
Optional: true,
Computed: true,
Elem: &Resource{
Schema: map[string]*Schema{
"list": &Schema{
Type: TypeList,
Optional: true,
Elem: &Schema{
Type: TypeString,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
if strings.HasPrefix(v.(string), "${") {
es = append(es, fmt.Errorf("should not have interpolations"))
}
return
},
},
},
},
},
},
},
Config: map[string]interface{}{
"outer": []map[string]interface{}{
{
"list": []interface{}{"${var.a}", "${var.b}", "c"},
},
},
},
Vars: map[string]string{
"var.a": "A",
"var.b": config.UnknownVariableValue,
},
Err: false,
},
}
for tn, tc := range cases {