cli: Fix diff for nested set unchanged elements
Unchanged elements in nested attributes backed by sets were previously misrendered as empty objects. This commit removes the additional brackets and adds a count of unchanged elements.
This commit is contained in:
parent
d30314d2b7
commit
2d0349d9a4
|
@ -569,6 +569,8 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff(
|
|||
|
||||
p.buf.WriteString(" = [")
|
||||
|
||||
var unchanged int
|
||||
|
||||
for it := all.ElementIterator(); it.Next(); {
|
||||
_, val := it.Element()
|
||||
var action plans.Action
|
||||
|
@ -598,12 +600,17 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff(
|
|||
newValue = val
|
||||
}
|
||||
|
||||
if action == plans.NoOp {
|
||||
unchanged++
|
||||
continue
|
||||
}
|
||||
|
||||
p.buf.WriteString("\n")
|
||||
p.buf.WriteString(strings.Repeat(" ", indent+4))
|
||||
p.writeActionSymbol(action)
|
||||
p.buf.WriteString("{")
|
||||
|
||||
if action != plans.NoOp && (p.pathForcesNewResource(path) || p.pathForcesNewResource(path[:len(path)-1])) {
|
||||
if p.pathForcesNewResource(path) || p.pathForcesNewResource(path[:len(path)-1]) {
|
||||
p.buf.WriteString(p.color.Color(forcesNewResourceCaption))
|
||||
}
|
||||
|
||||
|
@ -615,6 +622,7 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff(
|
|||
p.buf.WriteString("},")
|
||||
}
|
||||
p.buf.WriteString("\n")
|
||||
p.writeSkippedElems(unchanged, indent+4)
|
||||
p.buf.WriteString(strings.Repeat(" ", indent+2))
|
||||
p.buf.WriteString("]")
|
||||
|
||||
|
|
|
@ -2822,6 +2822,10 @@ func TestResourceChange_nestedSet(t *testing.T) {
|
|||
"mount_point": cty.StringVal("/var/diska"),
|
||||
"size": cty.NullVal(cty.String),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"mount_point": cty.StringVal("/var/diskb"),
|
||||
"size": cty.StringVal("100GB"),
|
||||
}),
|
||||
}),
|
||||
"root_block_device": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -2838,6 +2842,10 @@ func TestResourceChange_nestedSet(t *testing.T) {
|
|||
"mount_point": cty.StringVal("/var/diska"),
|
||||
"size": cty.StringVal("50GB"),
|
||||
}),
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
"mount_point": cty.StringVal("/var/diskb"),
|
||||
"size": cty.StringVal("100GB"),
|
||||
}),
|
||||
}),
|
||||
"root_block_device": cty.SetVal([]cty.Value{
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -2859,6 +2867,7 @@ func TestResourceChange_nestedSet(t *testing.T) {
|
|||
- {
|
||||
- mount_point = "/var/diska" -> null
|
||||
},
|
||||
# (1 unchanged element hidden)
|
||||
]
|
||||
id = "i-02ae66f368e8518a9"
|
||||
|
||||
|
|
Loading…
Reference in New Issue