Unmark before ElementIterator in couldHaveUnknownBlockPlaceholder
This is needed for cases where a variable may be fetched and become a member of a set, and thus the whole set is marked, which means ElementIterator will panic on unmarked values
This commit is contained in:
parent
5df11f2013
commit
e6daf3dbf1
|
@ -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
|
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 all other nesting modes, our value should be something iterable.
|
||||||
for it := v.ElementIterator(); it.Next(); {
|
for it := v.ElementIterator(); it.Next(); {
|
||||||
_, ev := it.Element()
|
_, ev := it.Element()
|
||||||
|
|
|
@ -194,6 +194,49 @@ func TestAssertObjectCompatible(t *testing.T) {
|
||||||
`.name: inconsistent values for sensitive attribute`,
|
`.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{
|
&configschema.Block{
|
||||||
Attributes: map[string]*configschema.Attribute{
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
|
Loading…
Reference in New Issue