Skip to content

Commit

Permalink
command: don't show old values for create diffs in plan
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apparentlymart committed May 8, 2016
1 parent 87475f1 commit 6fe0062
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions command/format_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ func formatPlanModuleExpand(
// resource header.
color := "yellow"
symbol := "~"
oldValues := true
switch rdiff.ChangeType() {
case terraform.DiffDestroyCreate:
color = "green"
symbol = "-/+"
case terraform.DiffCreate:
color = "green"
symbol = "+"
oldValues = false
case terraform.DiffDestroy:
color = "red"
symbol = "-"
Expand Down Expand Up @@ -134,13 +136,22 @@ func formatPlanModuleExpand(
newResource = opts.Color.Color(" [red](forces new resource)")
}

buf.WriteString(fmt.Sprintf(
" %s:%s %#v => %#v%s\n",
attrK,
strings.Repeat(" ", keyLen-len(attrK)),
attrDiff.Old,
v,
newResource))
if oldValues {
buf.WriteString(fmt.Sprintf(
" %s:%s %#v => %#v%s\n",
attrK,
strings.Repeat(" ", keyLen-len(attrK)),
attrDiff.Old,
v,
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
Expand Down

0 comments on commit 6fe0062

Please sign in to comment.