Skip to content

Commit 05a10f0

Browse files
committed
remove PreDiff and PostDiff hook calls
PreDiff and PostDiff hooks were designed to be called immediately before and after the PlanResourceChange calls to the provider. Probably due to the confusing legacy naming of the hooks, these were scattered about the nodes involved with planning, causing the hooks to be called in a number of places where they were designed, including data sources and destroy plans. Since these hooks are not used at all any longer anyway, we can removed the extra calls with no effect. If we choose in the future to call PlanResourceChange for resource destroy plans, the hooks can be re-inserted (even though they currently are unused) into the new code path which must diverge from the current combined path of managed and data sources.
1 parent dc668df commit 05a10f0

File tree

2 files changed

+2
-44
lines changed

2 files changed

+2
-44
lines changed

internal/terraform/context_apply_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,10 +1512,8 @@ func TestContext2Apply_destroyData(t *testing.T) {
15121512
}
15131513

15141514
wantHookCalls := []*testHookCall{
1515-
{"PreDiff", "data.null_data_source.testing"},
1516-
{"PostDiff", "data.null_data_source.testing"},
1517-
{"PreDiff", "data.null_data_source.testing"},
1518-
{"PostDiff", "data.null_data_source.testing"},
1515+
{"PreApply", "data.null_data_source.testing"},
1516+
{"PostApply", "data.null_data_source.testing"},
15191517
{"PostStateUpdate", ""},
15201518
}
15211519
if !reflect.DeepEqual(hook.Calls, wantHookCalls) {

internal/terraform/node_resource_abstract_instance.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,6 @@ func (n *NodeAbstractResourceInstance) planDestroy(ctx EvalContext, currentState
410410
return noop, nil
411411
}
412412

413-
// Call pre-diff hook
414-
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
415-
return h.PreDiff(
416-
absAddr, deposedKey.Generation(),
417-
currentState.Value,
418-
cty.NullVal(cty.DynamicPseudoType),
419-
)
420-
}))
421-
if diags.HasErrors() {
422-
return nil, diags
423-
}
424-
425413
// Plan is always the same for a destroy. We don't need the provider's
426414
// help for this one.
427415
plan := &plans.ResourceInstanceChange{
@@ -437,17 +425,6 @@ func (n *NodeAbstractResourceInstance) planDestroy(ctx EvalContext, currentState
437425
ProviderAddr: n.ResolvedProvider,
438426
}
439427

440-
// Call post-diff hook
441-
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
442-
return h.PostDiff(
443-
absAddr,
444-
deposedKey.Generation(),
445-
plan.Action,
446-
plan.Before,
447-
plan.After,
448-
)
449-
}))
450-
451428
return plan, diags
452429
}
453430

@@ -1567,13 +1544,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
15671544
}
15681545

15691546
proposedNewVal := objchange.PlannedDataResourceObject(schema, unmarkedConfigVal)
1570-
1571-
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
1572-
return h.PreDiff(n.Addr, states.CurrentGen, priorVal, proposedNewVal)
1573-
}))
1574-
if diags.HasErrors() {
1575-
return nil, nil, keyData, diags
1576-
}
15771547
proposedNewVal = proposedNewVal.MarkWithPaths(configMarkPaths)
15781548

15791549
// Apply detects that the data source will need to be read by the After
@@ -1601,13 +1571,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
16011571
return plannedChange, plannedNewState, keyData, diags
16021572
}
16031573

1604-
// While this isn't a "diff", continue to call this for data sources.
1605-
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
1606-
return h.PreDiff(n.Addr, states.CurrentGen, priorVal, configVal)
1607-
}))
1608-
if diags.HasErrors() {
1609-
return nil, nil, keyData, diags
1610-
}
16111574
// We have a complete configuration with no dependencies to wait on, so we
16121575
// can read the data source into the state.
16131576
newVal, readDiags := n.readDataSource(ctx, configVal)
@@ -1643,9 +1606,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
16431606
Status: states.ObjectReady,
16441607
}
16451608

1646-
diags = diags.Append(ctx.Hook(func(h Hook) (HookAction, error) {
1647-
return h.PostDiff(n.Addr, states.CurrentGen, plans.Update, priorVal, newVal)
1648-
}))
16491609
return nil, plannedNewState, keyData, diags
16501610
}
16511611

0 commit comments

Comments
 (0)