From e704da535e4603566e0f06f6f54fe2524399db3e Mon Sep 17 00:00:00 2001 From: Liam Cervante Date: Thu, 25 Jul 2024 08:04:24 +0200 Subject: [PATCH] stack: stacks should be applyable even if no components are (#35498) --- internal/rpcapi/stacks_test.go | 4 ++-- internal/stacks/stackruntime/plan.go | 12 +++--------- internal/stacks/stackruntime/plan_test.go | 16 ++++++++-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/internal/rpcapi/stacks_test.go b/internal/rpcapi/stacks_test.go index 06a66d3ef2..b6593183a2 100644 --- a/internal/rpcapi/stacks_test.go +++ b/internal/rpcapi/stacks_test.go @@ -449,13 +449,13 @@ func TestStacksPlanStackChanges(t *testing.T) { PlannedChange: &terraform1.PlannedChange{ Raw: []*anypb.Any{ mustMarshalAnyPb(&tfstackdata1.PlanApplyable{ - Applyable: false, + Applyable: true, }), }, Descriptions: []*terraform1.PlannedChange_ChangeDescription{ { Description: &terraform1.PlannedChange_ChangeDescription_PlanApplyable{ - PlanApplyable: false, + PlanApplyable: true, }, }, }, diff --git a/internal/stacks/stackruntime/plan.go b/internal/stacks/stackruntime/plan.go index 39ee9fd651..2481fbd527 100644 --- a/internal/stacks/stackruntime/plan.go +++ b/internal/stacks/stackruntime/plan.go @@ -39,7 +39,7 @@ func Plan(ctx context.Context, req *PlanRequest, resp *PlanResponse) { close(resp.PlannedChanges) // MUST be the last channel to close }() - var errored, applyable bool + var errored bool planTimestamp := time.Now().UTC() if req.ForcePlanTimestamp != nil { @@ -58,11 +58,6 @@ func Plan(ctx context.Context, req *PlanRequest, resp *PlanResponse) { main.PlanAll(ctx, stackeval.PlanOutput{ AnnouncePlannedChange: func(ctx context.Context, change stackplan.PlannedChange) { resp.PlannedChanges <- change - if componentChange, ok := change.(*stackplan.PlannedChangeComponentInstance); ok { - if componentChange.PlanApplyable { - applyable = true - } - } }, AnnounceDiagnostics: func(ctx context.Context, diags tfdiags.Diagnostics) { for _, diag := range diags { @@ -82,9 +77,8 @@ func Plan(ctx context.Context, req *PlanRequest, resp *PlanResponse) { resp.Diagnostics <- diag } - // An overall stack plan is applyable if at least one of its component - // instances is applyable and we had no error diagnostics. - resp.Applyable = !errored && applyable + // An overall stack plan is applyable if it has no error diagnostics. + resp.Applyable = !errored // Before we return we'll emit one more special planned change just to // remember in the raw plan sequence whether we considered this plan to be diff --git a/internal/stacks/stackruntime/plan_test.go b/internal/stacks/stackruntime/plan_test.go index 3b5ff95388..1047cd6194 100644 --- a/internal/stacks/stackruntime/plan_test.go +++ b/internal/stacks/stackruntime/plan_test.go @@ -359,7 +359,7 @@ func TestPlanWithVariableDefaults(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -891,7 +891,7 @@ func TestPlanWithEphemeralInputVariables(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -949,7 +949,7 @@ func TestPlanWithEphemeralInputVariables(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -1008,7 +1008,7 @@ func TestPlanVariableOutputRoundtripNested(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -2145,7 +2145,7 @@ func TestPlanWithDeferredResource(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeComponentInstance{ Addr: stackaddrs.Absolute( @@ -2787,7 +2787,7 @@ func TestPlanWithDeferredEmbeddedStackForEach(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -2933,7 +2933,7 @@ func TestPlanWithDeferredEmbeddedStackAndComponentForEach(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeHeader{ TerraformVersion: version.SemVer, @@ -3140,7 +3140,7 @@ func TestPlanWithDeferredProviderForEach(t *testing.T) { wantChanges := []stackplan.PlannedChange{ &stackplan.PlannedChangeApplyable{ - Applyable: false, + Applyable: true, }, &stackplan.PlannedChangeComponentInstance{ Addr: stackaddrs.Absolute(