Unverified Commit ec3058d5 authored by Alisdair McDiarmid's avatar Alisdair McDiarmid Committed by GitHub
Browse files

Merge pull request #29983 from hashicorp/alisdair/fix-nested-set-unchanged

cli: Fix diff for nested set unchanged elements
parents d30314d2 b562c4fb
Showing with 42 additions and 25 deletions
+42 -25
...@@ -569,6 +569,8 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff( ...@@ -569,6 +569,8 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff(
p.buf.WriteString(" = [") p.buf.WriteString(" = [")
var unchanged int
for it := all.ElementIterator(); it.Next(); { for it := all.ElementIterator(); it.Next(); {
_, val := it.Element() _, val := it.Element()
var action plans.Action var action plans.Action
...@@ -598,23 +600,29 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff( ...@@ -598,23 +600,29 @@ func (p *blockBodyDiffPrinter) writeNestedAttrDiff(
newValue = val newValue = val
} }
if action == plans.NoOp {
unchanged++
continue
}
p.buf.WriteString("\n") p.buf.WriteString("\n")
p.buf.WriteString(strings.Repeat(" ", indent+4)) p.buf.WriteString(strings.Repeat(" ", indent+4))
p.writeActionSymbol(action) p.writeActionSymbol(action)
p.buf.WriteString("{") 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)) p.buf.WriteString(p.color.Color(forcesNewResourceCaption))
} }
path := append(path, cty.IndexStep{Key: val}) path := append(path, cty.IndexStep{Key: val})
p.writeAttrsDiff(objS.Attributes, oldValue, newValue, indent+6, path, result) p.writeAttrsDiff(objS.Attributes, oldValue, newValue, indent+8, path, result)
p.buf.WriteString("\n") p.buf.WriteString("\n")
p.buf.WriteString(strings.Repeat(" ", indent+4)) p.buf.WriteString(strings.Repeat(" ", indent+6))
p.buf.WriteString("},") p.buf.WriteString("},")
} }
p.buf.WriteString("\n") p.buf.WriteString("\n")
p.writeSkippedElems(unchanged, indent+6)
p.buf.WriteString(strings.Repeat(" ", indent+2)) p.buf.WriteString(strings.Repeat(" ", indent+2))
p.buf.WriteString("]") p.buf.WriteString("]")
......
...@@ -2800,8 +2800,8 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2800,8 +2800,8 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [ ~ disks = [
+ { + {
+ mount_point = "/var/diska" + mount_point = "/var/diska"
}, },
] ]
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
...@@ -2822,6 +2822,10 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2822,6 +2822,10 @@ func TestResourceChange_nestedSet(t *testing.T) {
"mount_point": cty.StringVal("/var/diska"), "mount_point": cty.StringVal("/var/diska"),
"size": cty.NullVal(cty.String), "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{ "root_block_device": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
...@@ -2838,6 +2842,10 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2838,6 +2842,10 @@ func TestResourceChange_nestedSet(t *testing.T) {
"mount_point": cty.StringVal("/var/diska"), "mount_point": cty.StringVal("/var/diska"),
"size": cty.StringVal("50GB"), "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{ "root_block_device": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{ cty.ObjectVal(map[string]cty.Value{
...@@ -2853,12 +2861,13 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2853,12 +2861,13 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [ ~ disks = [
+ { + {
+ mount_point = "/var/diska" + mount_point = "/var/diska"
+ size = "50GB" + size = "50GB"
}, },
- { - {
- mount_point = "/var/diska" -> null - mount_point = "/var/diska" -> null
}, },
# (1 unchanged element hidden)
] ]
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
...@@ -2916,13 +2925,13 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2916,13 +2925,13 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [ ~ disks = [
- { # forces replacement - { # forces replacement
- mount_point = "/var/diska" -> null - mount_point = "/var/diska" -> null
- size = "50GB" -> null - size = "50GB" -> null
}, },
+ { # forces replacement + { # forces replacement
+ mount_point = "/var/diskb" + mount_point = "/var/diskb"
+ size = "50GB" + size = "50GB"
}, },
] ]
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
...@@ -2973,9 +2982,9 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -2973,9 +2982,9 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [ ~ disks = [
- { - {
- mount_point = "/var/diska" -> null - mount_point = "/var/diska" -> null
- size = "50GB" -> null - size = "50GB" -> null
}, },
] ]
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
...@@ -3062,9 +3071,9 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -3062,9 +3071,9 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
+ disks = [ + disks = [
+ { + {
+ mount_point = "/var/diska" + mount_point = "/var/diska"
+ size = "50GB" + size = "50GB"
}, },
] ]
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
...@@ -3118,9 +3127,9 @@ func TestResourceChange_nestedSet(t *testing.T) { ...@@ -3118,9 +3127,9 @@ func TestResourceChange_nestedSet(t *testing.T) {
~ ami = "ami-BEFORE" -> "ami-AFTER" ~ ami = "ami-BEFORE" -> "ami-AFTER"
~ disks = [ ~ disks = [
- { - {
- mount_point = "/var/diska" -> null - mount_point = "/var/diska" -> null
- size = "50GB" -> null - size = "50GB" -> null
}, },
] -> (known after apply) ] -> (known after apply)
id = "i-02ae66f368e8518a9" id = "i-02ae66f368e8518a9"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment