Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reify the list values before validation #13046

Merged
merged 2 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 42 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"testing"

"github.com/hashicorp/hil"
Expand Down Expand Up @@ -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 {
Expand Down