Skip to content

Commit 599cbf8

Browse files
ryanuberPaddy
authored andcommitted
backend/remote: display cost estimate and policy check whenever available
1 parent 2fc8cd5 commit 599cbf8

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

backend/remote/backend_common.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op
269269
return generalError("Failed to retrieve cost estimate", err)
270270
}
271271

272+
// If the run is canceled or errored, but the cost-estimate still has
273+
// no result, there is nothing further to render.
274+
if ce.Status != tfe.CostEstimateFinished {
275+
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
276+
return nil
277+
}
278+
}
279+
272280
switch ce.Status {
273281
case tfe.CostEstimateFinished:
274282
delta, err := strconv.ParseFloat(ce.DeltaMonthlyCost, 64)
@@ -324,18 +332,27 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope
324332
b.CLI.Output("\n------------------------------------------------------------------------\n")
325333
}
326334
for i, pc := range r.PolicyChecks {
327-
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
328-
if err != nil {
329-
return generalError("Failed to retrieve policy check logs", err)
330-
}
331-
reader := bufio.NewReaderSize(logs, 64*1024)
332-
333335
// Retrieve the policy check to get its current status.
334336
pc, err := b.client.PolicyChecks.Read(stopCtx, pc.ID)
335337
if err != nil {
336338
return generalError("Failed to retrieve policy check", err)
337339
}
338340

341+
// If the run is canceled or errored, but the policy check still has
342+
// no result, there is nothing further to render.
343+
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
344+
switch pc.Status {
345+
case tfe.PolicyPending, tfe.PolicyQueued, tfe.PolicyUnreachable:
346+
continue
347+
}
348+
}
349+
350+
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
351+
if err != nil {
352+
return generalError("Failed to retrieve policy check logs", err)
353+
}
354+
reader := bufio.NewReaderSize(logs, 64*1024)
355+
339356
var msgPrefix string
340357
switch pc.Scope {
341358
case tfe.PolicyScopeOrganization:

backend/remote/backend_plan.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,11 @@ in order to capture the filesystem context the remote workspace expects:
308308
return r, generalError("Failed to retrieve run", err)
309309
}
310310

311-
// Return if the run is canceled or errored. We return without
312-
// an error, even if the run errored, as the error is already
313-
// displayed by the output of the remote run.
314-
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
315-
return r, nil
316-
}
311+
// If the run is canceled or errored, we still continue to the
312+
// cost-estimation and policy check phases to ensure we render any
313+
// results available. In the case of a hard-failed policy check, the
314+
// status of the run will be "errored", but there is still policy
315+
// information which should be shown.
317316

318317
// Show any cost estimation output.
319318
if r.CostEstimate != nil {

0 commit comments

Comments
 (0)