diff --git a/backend/local/hook_count.go b/backend/local/hook_count.go index 9a58e91b48..4708159dc0 100644 --- a/backend/local/hook_count.go +++ b/backend/local/hook_count.go @@ -100,11 +100,6 @@ func (h *CountHook) PostDiff( return terraform.HookActionContinue, nil } - // Don't count anything for a Stub diff - if d.Stub { - return terraform.HookActionContinue, nil - } - switch d.ChangeType() { case terraform.DiffDestroyCreate: h.ToRemoveAndAdd += 1 diff --git a/backend/local/hook_count_test.go b/backend/local/hook_count_test.go index 488f1a2781..45e6e20d9c 100644 --- a/backend/local/hook_count_test.go +++ b/backend/local/hook_count_test.go @@ -241,42 +241,3 @@ func TestCountHookPostDiff_DataSource(t *testing.T) { expected, h) } } - -func TestCountHookPostDiff_IgnoreStub(t *testing.T) { - h := new(CountHook) - - resources := []*terraform.InstanceDiff{ - &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "foo.0": &terraform.ResourceAttrDiff{}, - "foo.1": &terraform.ResourceAttrDiff{}, - "foo.2": &terraform.ResourceAttrDiff{RequiresNew: true}, - }, - Stub: true, - }, - &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "foo.0": &terraform.ResourceAttrDiff{}, - "foo.1": &terraform.ResourceAttrDiff{}, - "foo.2": &terraform.ResourceAttrDiff{RequiresNew: true}, - }, - }, - } - - n := &terraform.InstanceInfo{} - - for _, d := range resources { - h.PostDiff(n, d) - } - - expected := new(CountHook) - expected.ToAdd = 1 - expected.ToChange = 0 - expected.ToRemoveAndAdd = 0 - expected.ToRemove = 0 - - if !reflect.DeepEqual(expected, h) { - t.Fatalf("Expected %#v, got %#v instead.", - expected, h) - } -} diff --git a/terraform/diff.go b/terraform/diff.go index 941c0fe9ce..a9fae6c2c8 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -373,11 +373,6 @@ type InstanceDiff struct { // mean to be used for additional data a resource may want to pass through. // The value here must only contain Go primitives and collections. Meta map[string]interface{} - - // Stub should be set when this diff exists only for purposes of providing a - // diff to various pre-plan or dry-run steps in the graph. A diff with this - // enabled should not be acted on in the plan. - Stub bool } func (d *InstanceDiff) Lock() { d.mu.Lock() } diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 083e63ca10..c35f9083f8 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -96,11 +96,13 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) { provider := *n.Provider // Call pre-diff hook - err := ctx.Hook(func(h Hook) (HookAction, error) { - return h.PreDiff(n.Info, state) - }) - if err != nil { - return nil, err + if !n.Stub { + err := ctx.Hook(func(h Hook) (HookAction, error) { + return h.PreDiff(n.Info, state) + }) + if err != nil { + return nil, err + } } // The state for the diff must never be nil @@ -163,17 +165,14 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) { return nil, err } - // Flag stub in the diff if set in the eval node. This ensures that this - // resource is skipped in post-diff hooks, such as count, etc, and is usually - // set in a pre-plan phase. - diff.Stub = n.Stub - // Call post-refresh hook - err = ctx.Hook(func(h Hook) (HookAction, error) { - return h.PostDiff(n.Info, diff) - }) - if err != nil { - return nil, err + if !n.Stub { + err = ctx.Hook(func(h Hook) (HookAction, error) { + return h.PostDiff(n.Info, diff) + }) + if err != nil { + return nil, err + } } // Update our output if we care