Merge pull request #27635 from hashicorp/pselle/obj-compatible-set

Unmark values in couldHaveUnknownBlockPlaceholder before iteration
This commit is contained in:
Pam Selle 2021-02-02 13:44:49 -05:00 committed by GitHub
commit 84f5b863ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -357,6 +357,10 @@ func couldHaveUnknownBlockPlaceholder(v cty.Value, blockS *configschema.NestedBl
return false // treated as if the list were empty, so we would see zero iterations below
}
// Unmark before we call ElementIterator in case this iterable is marked sensitive.
// This can arise in the case where a member of a Set is sensitive, and thus the
// whole Set is marked sensitive
v, _ := v.Unmark()
// For all other nesting modes, our value should be something iterable.
for it := v.ElementIterator(); it.Next(); {
_, ev := it.Element()

View File

@ -194,6 +194,49 @@ func TestAssertObjectCompatible(t *testing.T) {
`.name: inconsistent values for sensitive attribute`,
},
},
{
// This tests the codepath that leads to couldHaveUnknownBlockPlaceholder,
// where a set may be sensitive and need to be unmarked before it
// is iterated upon
&configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
"configuration": {
Nesting: configschema.NestingList,
Block: configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
"sensitive_fields": {
Nesting: configschema.NestingSet,
Block: schemaWithFoo,
},
},
},
},
},
},
cty.ObjectVal(map[string]cty.Value{
"configuration": cty.TupleVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"sensitive_fields": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("secret"),
}),
}).Mark("sensitive"),
}),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"configuration": cty.TupleVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"sensitive_fields": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("secret"),
}),
}).Mark("sensitive"),
}),
}),
}),
nil,
},
{
&configschema.Block{
Attributes: map[string]*configschema.Attribute{