Skip to content

Commit

Permalink
Don't save errored plans
Browse files Browse the repository at this point in the history
On further consideration, this is a nonsensical thing to do, and it doesn't
match the behavior of plain CLI!

Additionally, skip next steps message on failure.
  • Loading branch information
nfagerlund committed Jun 29, 2023
1 parent aad14b4 commit fecb608
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions internal/cloud/backend_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ func (b *Cloud) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operation
return nil, diags.Err()
}

// If the run errored, exit before checking whether to save a plan file
run, err := b.plan(stopCtx, cancelCtx, op, w)
if err != nil {
return run, err
}

// Save plan even if the run errored, as long as it actually exists
if run != nil && run.ID != "" && op.PlanOutPath != "" {
// Maybe save plan file
if op.PlanOutPath != "" {
bookmark := cloudplan.NewSavedPlanBookmark(run.ID, b.hostname)
saveErr := bookmark.Save(op.PlanOutPath)
// Maybe combine errors
if err != nil && saveErr != nil {
err = fmt.Errorf("%w\nAdditionally, an error occurred when saving the plan: %s", err, saveErr.Error())
} else if err == nil {
err = saveErr
}
err = bookmark.Save(op.PlanOutPath)
}

// Cloud integration currently doesn't support genconfig, but we might have
// saved a cloud plan file.
op.View.PlanNextStep(op.PlanOutPath, "")
// Only display next steps if everything succeeded
if err == nil {
// Cloud currently supports plan -out but not genconfig
op.View.PlanNextStep(op.PlanOutPath, "")
}

return run, err
}
Expand Down

0 comments on commit fecb608

Please sign in to comment.