Skip to content

Commit

Permalink
Added run task support for post plan run stage, removed pre apply
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebasslash committed Feb 1, 2022
1 parent d53f87a commit 307a904
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions internal/cloud/backend_plan.go
Expand Up @@ -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 pre-apply 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)
Expand All @@ -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
Expand Down

0 comments on commit 307a904

Please sign in to comment.