From 8701434b4d5fa042e8924f5aecfff416a4837c74 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 28 Nov 2016 13:49:10 -0800 Subject: [PATCH] command: plan formatting for deposed destroy --- command/format_plan.go | 13 ++++++++++--- command/format_plan_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/command/format_plan.go b/command/format_plan.go index e0020e648..98a07f63c 100644 --- a/command/format_plan.go +++ b/command/format_plan.go @@ -114,14 +114,21 @@ func formatPlanModuleExpand( symbol = "-" } - taintStr := "" + var extraAttr []string if rdiff.DestroyTainted { - taintStr = " (tainted)" + extraAttr = append(extraAttr, "tainted") + } + if rdiff.DestroyDeposed { + extraAttr = append(extraAttr, "deposed") + } + var extraStr string + if len(extraAttr) > 0 { + extraStr = fmt.Sprintf(" (%s)", strings.Join(extraAttr, ", ")) } buf.WriteString(opts.Color.Color(fmt.Sprintf( "[%s]%s %s%s\n", - color, symbol, name, taintStr))) + color, symbol, name, extraStr))) // Get all the attributes that are changing, and sort them. Also // determine the longest key so that we can align them all. diff --git a/command/format_plan_test.go b/command/format_plan_test.go index a79c873eb..3784f18c5 100644 --- a/command/format_plan_test.go +++ b/command/format_plan_test.go @@ -8,6 +8,41 @@ import ( "github.com/mitchellh/colorstring" ) +// Test that a root level data source gets a special plan output on create +func TestFormatPlan_destroyDeposed(t *testing.T) { + plan := &terraform.Plan{ + Diff: &terraform.Diff{ + Modules: []*terraform.ModuleDiff{ + &terraform.ModuleDiff{ + Path: []string{"root"}, + Resources: map[string]*terraform.InstanceDiff{ + "aws_instance.foo": &terraform.InstanceDiff{ + DestroyDeposed: true, + }, + }, + }, + }, + }, + } + opts := &FormatPlanOpts{ + Plan: plan, + Color: &colorstring.Colorize{ + Colors: colorstring.DefaultColors, + Disable: true, + }, + ModuleDepth: 1, + } + + actual := FormatPlan(opts) + + expected := strings.TrimSpace(` +- aws_instance.foo (deposed) + `) + if actual != expected { + t.Fatalf("expected:\n\n%s\n\ngot:\n\n%s", expected, actual) + } +} + // Test that a root level data source gets a special plan output on create func TestFormatPlan_rootDataSource(t *testing.T) { plan := &terraform.Plan{