@@ -22,6 +22,7 @@ import (
2222 "github.com/hashicorp/terraform/internal/providers"
2323 "github.com/hashicorp/terraform/internal/stacks/stackaddrs"
2424 "github.com/hashicorp/terraform/internal/stacks/stackplan"
25+ "github.com/hashicorp/terraform/internal/stacks/stackruntime/hooks"
2526 "github.com/hashicorp/terraform/internal/stacks/stackstate"
2627 "github.com/hashicorp/terraform/internal/states"
2728 "github.com/hashicorp/terraform/internal/terraform"
@@ -192,6 +193,7 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
192193 ctx , c .tracingName ()+ " modules" , & c .moduleTreePlan ,
193194 func (ctx context.Context ) (* plans.Plan , tfdiags.Diagnostics ) {
194195 var diags tfdiags.Diagnostics
196+ h := hooksFromContext (ctx )
195197
196198 if c .mode == plans .DestroyMode {
197199
@@ -203,7 +205,13 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
203205 // and never applied, or that it was previously destroyed
204206 // via an earlier destroy operation.
205207 //
206- // Return a dummy plan:
208+ // Return a dummy plan and send dummy events:
209+ hookSingle (ctx , h .PendingComponentInstancePlan , c .Addr ())
210+ seq , ctx := hookBegin (ctx , h .BeginComponentInstancePlan , h .ContextAttach , c .Addr ())
211+ hookMore (ctx , seq , h .ReportComponentInstancePlanned , & hooks.ComponentInstanceChange {
212+ Addr : c .Addr (),
213+ })
214+ hookMore (ctx , seq , h .EndComponentInstancePlan , c .Addr ())
207215 return & plans.Plan {
208216 UIMode : plans .DestroyMode ,
209217 Complete : true ,
@@ -220,7 +228,6 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
220228 // outputs from this component can read from the refresh result
221229 // without causing a cycle.
222230
223- h := hooksFromContext (ctx )
224231 hookSingle (ctx , h .PendingComponentInstancePlan , c .Addr ())
225232 seq , planCtx := hookBegin (ctx , h .BeginComponentInstancePlan , h .ContextAttach , c .Addr ())
226233
@@ -336,7 +343,6 @@ func (c *ComponentInstance) CheckModuleTreePlan(ctx context.Context) (*plans.Pla
336343 }
337344 }
338345
339- h := hooksFromContext (ctx )
340346 hookSingle (ctx , h .PendingComponentInstancePlan , c .Addr ())
341347 seq , ctx := hookBegin (ctx , h .BeginComponentInstancePlan , h .ContextAttach , c .Addr ())
342348 plan , moreDiags := PlanComponentInstance (ctx , c .main , c .PlanPrevState (), opts , []terraform.Hook {
@@ -382,6 +388,15 @@ func (c *ComponentInstance) ApplyModuleTreePlan(ctx context.Context, plan *plans
382388
383389 // If we're destroying and there's nothing to destroy, then we can
384390 // consider this a no-op.
391+ // We still need to report through the hooks that this component instance has been handled.
392+ h := hooksFromContext (ctx )
393+ hookSingle (ctx , hooksFromContext (ctx ).PendingComponentInstanceApply , c .Addr ())
394+ seq , ctx := hookBegin (ctx , h .BeginComponentInstanceApply , h .ContextAttach , c .Addr ())
395+ hookMore (ctx , seq , h .ReportComponentInstanceApplied , & hooks.ComponentInstanceChange {
396+ Addr : c .Addr (),
397+ })
398+ hookMore (ctx , seq , h .EndComponentInstanceApply , c .Addr ())
399+
385400 return & ComponentInstanceApplyResult {
386401 FinalState : plan .PriorState , // after refresh
387402 AffectedResourceInstanceObjects : resourceInstanceObjectsAffectedByStackPlan (stackPlan ),
0 commit comments