@@ -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
@@ -1381,6 +1358,13 @@ func (n *NodeAbstractResourceInstance) readDataSource(ctx EvalContext, configVal
13811358 // to actually call the provider to read the data.
13821359 log .Printf ("[TRACE] readDataSource: %s configuration is complete, so reading from provider" , n .Addr )
13831360
1361+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1362+ return h .PreApply (n .Addr , states .CurrentGen , plans .Read , cty .NullVal (configVal .Type ()), configVal )
1363+ }))
1364+ if diags .HasErrors () {
1365+ return newVal , diags
1366+ }
1367+
13841368 resp := provider .ReadDataSource (providers.ReadDataSourceRequest {
13851369 TypeName : n .Addr .ContainingResource ().Resource .Type ,
13861370 Config : configVal ,
@@ -1445,6 +1429,10 @@ func (n *NodeAbstractResourceInstance) readDataSource(ctx EvalContext, configVal
14451429 newVal = newVal .MarkWithPaths (pvm )
14461430 }
14471431
1432+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1433+ return h .PostApply (n .Addr , states .CurrentGen , newVal , diags .Err ())
1434+ }))
1435+
14481436 return newVal , diags
14491437}
14501438
@@ -1556,13 +1544,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
15561544 }
15571545
15581546 proposedNewVal := objchange .PlannedDataResourceObject (schema , unmarkedConfigVal )
1559-
1560- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1561- return h .PreDiff (n .Addr , states .CurrentGen , priorVal , proposedNewVal )
1562- }))
1563- if diags .HasErrors () {
1564- return nil , nil , keyData , diags
1565- }
15661547 proposedNewVal = proposedNewVal .MarkWithPaths (configMarkPaths )
15671548
15681549 // Apply detects that the data source will need to be read by the After
@@ -1590,13 +1571,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
15901571 return plannedChange , plannedNewState , keyData , diags
15911572 }
15921573
1593- // While this isn't a "diff", continue to call this for data sources.
1594- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1595- return h .PreDiff (n .Addr , states .CurrentGen , priorVal , configVal )
1596- }))
1597- if diags .HasErrors () {
1598- return nil , nil , keyData , diags
1599- }
16001574 // We have a complete configuration with no dependencies to wait on, so we
16011575 // can read the data source into the state.
16021576 newVal , readDiags := n .readDataSource (ctx , configVal )
@@ -1632,9 +1606,6 @@ func (n *NodeAbstractResourceInstance) planDataSource(ctx EvalContext, currentSt
16321606 Status : states .ObjectReady ,
16331607 }
16341608
1635- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1636- return h .PostDiff (n .Addr , states .CurrentGen , plans .Update , priorVal , newVal )
1637- }))
16381609 return nil , plannedNewState , keyData , diags
16391610}
16401611
@@ -1703,13 +1674,6 @@ func (n *NodeAbstractResourceInstance) applyDataSource(ctx EvalContext, planned
17031674 return nil , keyData , diags
17041675 }
17051676
1706- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1707- return h .PreApply (n .Addr , states .CurrentGen , planned .Action , planned .Before , planned .After )
1708- }))
1709- if diags .HasErrors () {
1710- return nil , keyData , diags
1711- }
1712-
17131677 config := * n .Config
17141678 schema , _ := providerSchema .SchemaForResourceAddr (n .Addr .ContainingResource ().Resource )
17151679 if schema == nil {
@@ -1751,10 +1715,6 @@ func (n *NodeAbstractResourceInstance) applyDataSource(ctx EvalContext, planned
17511715 Status : states .ObjectReady ,
17521716 }
17531717
1754- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1755- return h .PostApply (n .Addr , states .CurrentGen , newVal , diags .Err ())
1756- }))
1757-
17581718 return state , keyData , diags
17591719}
17601720
0 commit comments