diff --git a/command/format/plan.go b/command/format/plan.go index 728345e0a..65d2c9d27 100644 --- a/command/format/plan.go +++ b/command/format/plan.go @@ -311,7 +311,7 @@ func formatPlanInstanceDiff(buf *bytes.Buffer, r *InstanceDiff, keyLen int, colo updateMsg := "" switch { - case attr.ForcesNew && r.Action == terraform.DiffDestroy: + case attr.ForcesNew && r.Action == terraform.DiffDestroyCreate: updateMsg = colorizer.Color(" [red](forces new resource)") case attr.Sensitive && oldValues: updateMsg = colorizer.Color(" [yellow](attribute changed)") diff --git a/command/format/plan_test.go b/command/format/plan_test.go index 7ee380261..0a2dc1e36 100644 --- a/command/format/plan_test.go +++ b/command/format/plan_test.go @@ -509,6 +509,41 @@ func TestPlan_displayInterpolations(t *testing.T) { } } +// Ensure that (forces new resource) text is included +// https://github.com/hashicorp/terraform/issues/16035 +func TestPlan_forcesNewResource(t *testing.T) { + plan := &terraform.Plan{ + Diff: &terraform.Diff{ + Modules: []*terraform.ModuleDiff{ + &terraform.ModuleDiff{ + Path: []string{"root"}, + Resources: map[string]*terraform.InstanceDiff{ + "test_resource.foo": &terraform.InstanceDiff{ + Destroy: true, + Attributes: map[string]*terraform.ResourceAttrDiff{ + "A": &terraform.ResourceAttrDiff{ + New: "B", + RequiresNew: true, + }, + }, + }, + }, + }, + }, + }, + } + dispPlan := NewPlan(plan) + actual := dispPlan.Format(disabledColorize) + + expected := strings.TrimSpace(` +-/+ test_resource.foo (new resource required) + A: "" => "B" (forces new resource) + `) + 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 TestPlan_rootDataSource(t *testing.T) { plan := &terraform.Plan{