plans/objchange: Don't panic when a prior value with a set is null
ProposedNewObject intentionally replaces a null prior with an unknown prior in order to easily fill in unknown values where they "show through" under values not set explicitly in config, but it was failing to handle that situation when dealing with nested blocks that are backed by sets.
This commit is contained in:
parent
628c3a38b9
commit
9b4b43c077
|
@ -186,7 +186,10 @@ func ProposedNewObject(schema *configschema.Block, prior, config cty.Value) cty.
|
|||
// this means that any config change produces an entirely new
|
||||
// nested object, and we only propagate prior computed values
|
||||
// if the non-computed attribute values are identical.
|
||||
cmpVals := setElementCompareValues(&blockType.Block, priorV, false)
|
||||
var cmpVals [][2]cty.Value
|
||||
if priorV.IsKnown() && !priorV.IsNull() {
|
||||
cmpVals = setElementCompareValues(&blockType.Block, priorV, false)
|
||||
}
|
||||
if l := configV.LengthInt(); l > 0 {
|
||||
used := make([]bool, len(cmpVals)) // track used elements in case multiple have the same compare value
|
||||
newVals := make([]cty.Value, 0, l)
|
||||
|
|
|
@ -65,6 +65,42 @@ func TestProposedNewObject(t *testing.T) {
|
|||
}),
|
||||
}),
|
||||
},
|
||||
"no prior with set": {
|
||||
// This one is here because our handling of sets is more complex
|
||||
// than others (due to the fuzzy correlation heuristic) and
|
||||
// historically that caused us some panic-related grief.
|
||||
&configschema.Block{
|
||||
BlockTypes: map[string]*configschema.NestedBlock{
|
||||
"baz": {
|
||||
Nesting: configschema.NestingSet,
|
||||
Block: configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"boz": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
cty.NullVal(cty.DynamicPseudoType),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"baz": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"boz": cty.StringVal("world"),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"baz": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"boz": cty.StringVal("world"),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
"prior attributes": {
|
||||
&configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
|
Loading…
Reference in New Issue