command: don't show old values for create diffs in plan

New resources logically don't have "old values" for their attributes, so
showing them as updates from the empty string is misleading and confusing.

Instead, we'll skip showing the old value in a creation diff.
This commit is contained in:
Martin Atkins 2016-05-08 00:03:41 -07:00
parent 5d27a5b3e2
commit bfee4b0295
1 changed files with 18 additions and 7 deletions

View File

@ -87,6 +87,7 @@ func formatPlanModuleExpand(
// resource header. // resource header.
color := "yellow" color := "yellow"
symbol := "~" symbol := "~"
oldValues := true
switch rdiff.ChangeType() { switch rdiff.ChangeType() {
case terraform.DiffDestroyCreate: case terraform.DiffDestroyCreate:
color = "green" color = "green"
@ -94,6 +95,7 @@ func formatPlanModuleExpand(
case terraform.DiffCreate: case terraform.DiffCreate:
color = "green" color = "green"
symbol = "+" symbol = "+"
oldValues = false
case terraform.DiffDestroy: case terraform.DiffDestroy:
color = "red" color = "red"
symbol = "-" symbol = "-"
@ -134,6 +136,7 @@ func formatPlanModuleExpand(
newResource = opts.Color.Color(" [red](forces new resource)") newResource = opts.Color.Color(" [red](forces new resource)")
} }
if oldValues {
buf.WriteString(fmt.Sprintf( buf.WriteString(fmt.Sprintf(
" %s:%s %#v => %#v%s\n", " %s:%s %#v => %#v%s\n",
attrK, attrK,
@ -141,6 +144,14 @@ func formatPlanModuleExpand(
attrDiff.Old, attrDiff.Old,
v, v,
newResource)) newResource))
} else {
buf.WriteString(fmt.Sprintf(
" %s:%s %#v%s\n",
attrK,
strings.Repeat(" ", keyLen-len(attrK)),
v,
newResource))
}
} }
// Write the reset color so we don't overload the user's terminal // Write the reset color so we don't overload the user's terminal