From fbc34005baa29c590906a159bbaebcaa6a60e089 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 26 Jul 2023 08:04:13 -0700 Subject: [PATCH] stackeval: Emit PlannedChange for each component instance We need to explicitly announce each component instance that we find declared in the stack configuration before we announce any resource instances that belong to it, because callers will rely on this message to create a link between the component instance address on each resource instance and the unexpanded component addresses previously announced by the "find stack components" static analysis call. --- .../internal/stackeval/component_instance.go | 11 +++++++++++ internal/stacks/stackruntime/plan_test.go | 9 +++++++++ 2 files changed, 20 insertions(+) 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, },