core: Skip diff hooks for stubs on eval altogether

Rather than overloading InstanceDiff with a "Stub" attribute that is
going to be largely meaningless, we are just going to skip
pre/post-diff hooks altogether. This is under the notion that we will
eventually not need to "stub" a diff for scale-out, stateless nodes on
refresh at all, so diff behaviour won't be necessary at that point, so
we should not assume that hooks will run at this stage anyway.

Also as part of this removed the CountHook test that is now failing
because CountHook is out of scope of the new behaviour.
This commit is contained in:
Chris Marchesi 2017-06-24 08:01:17 -07:00
parent 50cd33f781
commit 5654a676d9
4 changed files with 14 additions and 64 deletions

View File

@ -100,11 +100,6 @@ func (h *CountHook) PostDiff(
return terraform.HookActionContinue, nil return terraform.HookActionContinue, nil
} }
// Don't count anything for a Stub diff
if d.Stub {
return terraform.HookActionContinue, nil
}
switch d.ChangeType() { switch d.ChangeType() {
case terraform.DiffDestroyCreate: case terraform.DiffDestroyCreate:
h.ToRemoveAndAdd += 1 h.ToRemoveAndAdd += 1

View File

@ -241,42 +241,3 @@ func TestCountHookPostDiff_DataSource(t *testing.T) {
expected, h) 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)
}
}

View File

@ -373,11 +373,6 @@ type InstanceDiff struct {
// mean to be used for additional data a resource may want to pass through. // mean to be used for additional data a resource may want to pass through.
// The value here must only contain Go primitives and collections. // The value here must only contain Go primitives and collections.
Meta map[string]interface{} 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() } func (d *InstanceDiff) Lock() { d.mu.Lock() }

View File

@ -96,11 +96,13 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
provider := *n.Provider provider := *n.Provider
// Call pre-diff hook // Call pre-diff hook
err := ctx.Hook(func(h Hook) (HookAction, error) { if !n.Stub {
return h.PreDiff(n.Info, state) err := ctx.Hook(func(h Hook) (HookAction, error) {
}) return h.PreDiff(n.Info, state)
if err != nil { })
return nil, err if err != nil {
return nil, err
}
} }
// The state for the diff must never be nil // The state for the diff must never be nil
@ -163,17 +165,14 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
return nil, err 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 // Call post-refresh hook
err = ctx.Hook(func(h Hook) (HookAction, error) { if !n.Stub {
return h.PostDiff(n.Info, diff) err = ctx.Hook(func(h Hook) (HookAction, error) {
}) return h.PostDiff(n.Info, diff)
if err != nil { })
return nil, err if err != nil {
return nil, err
}
} }
// Update our output if we care // Update our output if we care