command/format: fix missing elements at the end of lists in diffs
This commit is contained in:
parent
3e00447789
commit
a895a42f85
|
@ -1086,8 +1086,8 @@ func ctySequenceDiff(old, new []cty.Value) []*plans.Change {
|
|||
var oldI, newI, lcsI int
|
||||
for oldI < len(old) || newI < len(new) || lcsI < len(lcs) {
|
||||
for oldI < len(old) && (lcsI >= len(lcs) || !old[oldI].RawEquals(lcs[lcsI])) {
|
||||
isObjectDiff := old[oldI].Type().IsObjectType() && (newI >= len(new) || new[newI].Type().IsObjectType())
|
||||
if isObjectDiff && newI < len(new) {
|
||||
isObjectDiff := old[oldI].Type().IsObjectType() && newI < len(new) && new[newI].Type().IsObjectType() && (lcsI >= len(lcs) || !new[newI].RawEquals(lcs[lcsI]))
|
||||
if isObjectDiff {
|
||||
ret = append(ret, &plans.Change{
|
||||
Action: plans.Update,
|
||||
Before: old[oldI],
|
||||
|
|
|
@ -888,11 +888,11 @@ func TestResourceChange_JSON(t *testing.T) {
|
|||
Mode: addrs.ManagedResourceMode,
|
||||
Before: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.StringVal("i-02ae66f368e8518a9"),
|
||||
"json_field": cty.StringVal(`[{"one": "111"}, {"two": "222"}]`),
|
||||
"json_field": cty.StringVal(`[{"one": "111"}, {"two": "222"}, {"three": "333"}]`),
|
||||
}),
|
||||
After: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": cty.UnknownVal(cty.String),
|
||||
"json_field": cty.StringVal(`[{"one": "111"}]`),
|
||||
"json_field": cty.StringVal(`[{"one": "111"}, {"three": "333"}]`),
|
||||
}),
|
||||
Schema: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
@ -913,6 +913,9 @@ func TestResourceChange_JSON(t *testing.T) {
|
|||
- {
|
||||
- two = "222"
|
||||
},
|
||||
{
|
||||
three = "333"
|
||||
},
|
||||
]
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue