@@ -1381,6 +1381,13 @@ func (n *NodeAbstractResourceInstance) readDataSource(ctx EvalContext, configVal
13811381 // to actually call the provider to read the data.
13821382 log .Printf ("[TRACE] readDataSource: %s configuration is complete, so reading from provider" , n .Addr )
13831383
1384+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1385+ return h .PreApply (n .Addr , states .CurrentGen , plans .Read , cty .NullVal (configVal .Type ()), configVal )
1386+ }))
1387+ if diags .HasErrors () {
1388+ return newVal , diags
1389+ }
1390+
13841391 resp := provider .ReadDataSource (providers.ReadDataSourceRequest {
13851392 TypeName : n .Addr .ContainingResource ().Resource .Type ,
13861393 Config : configVal ,
@@ -1445,6 +1452,10 @@ func (n *NodeAbstractResourceInstance) readDataSource(ctx EvalContext, configVal
14451452 newVal = newVal .MarkWithPaths (pvm )
14461453 }
14471454
1455+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1456+ return h .PostApply (n .Addr , states .CurrentGen , newVal , diags .Err ())
1457+ }))
1458+
14481459 return newVal , diags
14491460}
14501461
@@ -1703,13 +1714,6 @@ func (n *NodeAbstractResourceInstance) applyDataSource(ctx EvalContext, planned
17031714 return nil , keyData , diags
17041715 }
17051716
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-
17131717 config := * n .Config
17141718 schema , _ := providerSchema .SchemaForResourceAddr (n .Addr .ContainingResource ().Resource )
17151719 if schema == nil {
@@ -1751,10 +1755,6 @@ func (n *NodeAbstractResourceInstance) applyDataSource(ctx EvalContext, planned
17511755 Status : states .ObjectReady ,
17521756 }
17531757
1754- diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
1755- return h .PostApply (n .Addr , states .CurrentGen , newVal , diags .Err ())
1756- }))
1757-
17581758 return state , keyData , diags
17591759}
17601760
0 commit comments