Converting ListVal to ListVal instead of TupleVal in setElementCompareValue

This commit is contained in:
Alexander Ovechkin 2020-09-04 15:46:40 +03:00 committed by James Bardin
parent 31033001a8
commit 8fbb4d0163
2 changed files with 66 additions and 2 deletions

View File

@ -357,13 +357,13 @@ func setElementCompareValue(schema *configschema.Block, v cty.Value, isConfig bo
// set and we've not changed the types of any elements here. // set and we've not changed the types of any elements here.
attrs[name] = cty.SetVal(elems) attrs[name] = cty.SetVal(elems)
} else { } else {
attrs[name] = cty.TupleVal(elems) attrs[name] = cty.ListVal(elems)
} }
} else { } else {
if blockType.Nesting == configschema.NestingSet { if blockType.Nesting == configschema.NestingSet {
attrs[name] = cty.SetValEmpty(blockType.Block.ImpliedType()) attrs[name] = cty.SetValEmpty(blockType.Block.ImpliedType())
} else { } else {
attrs[name] = cty.EmptyTupleVal attrs[name] = cty.ListValEmpty(blockType.Block.ImpliedType())
} }
} }

View File

@ -572,6 +572,70 @@ func TestProposedNewObject(t *testing.T) {
}), }),
}), }),
}, },
"nested list in sed": {
&configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
"foo": {
Nesting: configschema.NestingSet,
Block: configschema.Block{
BlockTypes: map[string]*configschema.NestedBlock{
"bar": {
Nesting: configschema.NestingList,
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"baz": {
Type: cty.String,
},
"qux": {
Type: cty.String,
Computed: true,
Optional: true,
},
},
},
},
},
},
},
},
},
cty.ObjectVal(map[string]cty.Value{
"foo": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"bar": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"baz": cty.StringVal("beep"),
"qux": cty.StringVal("boop"),
}),
}),
}),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"foo": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"bar": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"baz": cty.StringVal("beep"),
"qux": cty.NullVal(cty.String),
}),
}),
}),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"foo": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"bar": cty.ListVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"baz": cty.StringVal("beep"),
"qux": cty.StringVal("boop"),
}),
}),
}),
}),
}),
},
} }
for name, test := range tests { for name, test := range tests {