command: plan formatting for deposed destroy

This commit is contained in:
Mitchell Hashimoto 2016-11-28 13:49:10 -08:00
parent 41c56ad002
commit 8701434b4d
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 45 additions and 3 deletions

View File

@ -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.

View File

@ -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{