From 10c5a0de57d491a31b568879fbe5820e60bfdceb Mon Sep 17 00:00:00 2001 From: Sebastian Rivera Date: Tue, 1 Feb 2022 16:41:29 -0500 Subject: [PATCH] Added run task support for post plan run stage, removed pre apply This commit stems from the change to make post plan the default run task stage, at the time of this commit's writing! Since pre apply is under internal revision, we have removed the block that polls the pre apply stage until the team decides to re-add support for pre apply run tasks. --- internal/cloud/backend_plan.go | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/internal/cloud/backend_plan.go b/internal/cloud/backend_plan.go index 32b35a413c75..206093c40712 100644 --- a/internal/cloud/backend_plan.go +++ b/internal/cloud/backend_plan.go @@ -346,6 +346,22 @@ in order to capture the filesystem context the remote workspace expects: // status of the run will be "errored", but there is still policy // information which should be shown. + // Await post-plan run tasks + integration := &IntegrationContext{ + B: b, + StopContext: stopCtx, + CancelContext: cancelCtx, + Op: op, + Run: r, + } + + if stageID := getTaskStageIDByName(r.TaskStages, tfe.PostPlan); stageID != nil { + err = b.runTasks(integration, integration.BeginOutput("Run Tasks (post-plan)"), *stageID) + if err != nil { + return r, err + } + } + // Show any cost estimation output. if r.CostEstimate != nil { err = b.costEstimate(stopCtx, cancelCtx, op, r) @@ -362,28 +378,14 @@ in order to capture the filesystem context the remote workspace expects: } } - // Await pre-apply run tasks - if len(r.TaskStages) > 0 { - integration := &IntegrationContext{ - B: b, - StopContext: stopCtx, - CancelContext: cancelCtx, - Op: op, - Run: r, - } - - if stageID := getTaskStageIDByName(r.TaskStages, tfe.PreApply); stageID != nil { - err = b.runTasks(integration, integration.BeginOutput("Run Tasks (pre-apply)"), *stageID) - if err != nil { - return r, err - } - } - } - return r, nil } func getTaskStageIDByName(stages []*tfe.TaskStage, stageName tfe.Stage) *string { + if len(stages) == 0 { + return nil + } + for _, stage := range stages { if stage.Stage == stageName { return &stage.ID