Merge pull request #13046 from hashicorp/jbardin/GH-12892
reify the list values before validation
This commit is contained in:
commit
399715e1b7
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue