mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
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:
parent
50cd33f781
commit
5654a676d9
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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() }
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user