From a895a42f851ed50698f6b61ab9c2e10f1c640eb1 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Fri, 8 Nov 2019 17:05:23 -0700 Subject: [PATCH] command/format: fix missing elements at the end of lists in diffs --- command/format/diff.go | 4 ++-- command/format/diff_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/command/format/diff.go b/command/format/diff.go index 92d33294d..18796ee5b 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 cd1ae9f10..991a62fba 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" + }, ] ) }