@@ -255,6 +255,10 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
255255 instanceRefreshState , readDiags = n .readResourceInstanceState (ctx , addr )
256256 diags = diags .Append (readDiags )
257257 if diags .HasErrors () {
258+ // Pre-Diff error hook
259+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
260+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
261+ }))
258262 return diags
259263 }
260264 }
@@ -267,12 +271,20 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
267271 // refresh step below.
268272 diags = diags .Append (n .writeResourceInstanceState (ctx , instanceRefreshState , prevRunState ))
269273 if diags .HasErrors () {
274+ // Pre-Diff error hook
275+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
276+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
277+ }))
270278 return diags
271279 }
272280 // Also the refreshState, because that should still reflect schema upgrades
273281 // even if it doesn't reflect upstream changes.
274282 diags = diags .Append (n .writeResourceInstanceState (ctx , instanceRefreshState , refreshState ))
275283 if diags .HasErrors () {
284+ // Pre-Diff error hook
285+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
286+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
287+ }))
276288 return diags
277289 }
278290 }
@@ -319,6 +331,10 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
319331 }
320332
321333 if diags .HasErrors () {
334+ // Pre-Diff error hook
335+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
336+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
337+ }))
322338 return diags
323339 }
324340 }
@@ -329,6 +345,10 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
329345 // sure we still update any changes to CreateBeforeDestroy.
330346 diags = diags .Append (n .writeResourceInstanceState (ctx , instanceRefreshState , refreshState ))
331347 if diags .HasErrors () {
348+ // Pre-Diff error hook
349+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
350+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
351+ }))
332352 return diags
333353 }
334354 }
@@ -349,6 +369,10 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext)
349369
350370 diags = diags .Append (n .replaceTriggered (ctx , repData ))
351371 if diags .HasErrors () {
372+ // Pre-Diff error hook
373+ diags = diags .Append (ctx .Hook (func (h Hook ) (HookAction , error ) {
374+ return h .PreDiff (n .HookResourceIdentity (), addrs .NotDeposed , cty .DynamicVal , cty .DynamicVal , diags .Err ())
375+ }))
352376 return diags
353377 }
354378
0 commit comments