diff --git a/internal/stacks/stackruntime/internal/stackeval/component_instance.go b/internal/stacks/stackruntime/internal/stackeval/component_instance.go index 64ab813497..d10fd52151 100644 --- a/internal/stacks/stackruntime/internal/stackeval/component_instance.go +++ b/internal/stacks/stackruntime/internal/stackeval/component_instance.go @@ -269,6 +269,17 @@ func (c *ComponentInstance) PlanChanges(ctx context.Context) ([]stackplan.Planne var changes []stackplan.PlannedChange var diags tfdiags.Diagnostics + // We must always at least announce that the component instance exists, + // and that must come before any resource instance changes referring to it. + changes = append(changes, &stackplan.PlannedChangeComponentInstance{ + Addr: c.Addr(), + + // FIXME: Once we actually have a prior state this should vary + // depending on whether the same component instance existed in + // the prior state. + Action: plans.Create, + }) + _, moreDiags := c.CheckInputVariableValues(ctx, PlanPhase) diags = diags.Append(moreDiags) diff --git a/internal/stacks/stackruntime/plan_test.go b/internal/stacks/stackruntime/plan_test.go index dbd99404df..39ded6d445 100644 --- a/internal/stacks/stackruntime/plan_test.go +++ b/internal/stacks/stackruntime/plan_test.go @@ -51,6 +51,15 @@ func TestPlanWithSingleResource(t *testing.T) { &stackplan.PlannedChangeApplyable{ Applyable: true, }, + &stackplan.PlannedChangeComponentInstance{ + Addr: stackaddrs.Absolute( + stackaddrs.RootStackInstance, + stackaddrs.ComponentInstance{ + Component: stackaddrs.Component{Name: "self"}, + }, + ), + Action: plans.Create, + }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, },