diff --git a/command/format/diff.go b/command/format/diff.go index 92d33294d4..18796ee5bf 100644 --- a/command/format/diff.go +++ b/command/format/diff.go @@ -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], diff --git a/command/format/diff_test.go b/command/format/diff_test.go index cd1ae9f101..991a62fbad 100644 --- a/command/format/diff_test.go +++ b/command/format/diff_test.go @@ -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" + }, ] ) }