Merge pull request #24655 from hashicorp/b-remote-policy-check-race
backend/remote: display cost estimate and policy check whenever available
This commit is contained in:
commit
dcbd835ac3
|
@ -269,6 +269,14 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op
|
|||
return generalError("Failed to retrieve cost estimate", err)
|
||||
}
|
||||
|
||||
// If the run is canceled or errored, but the cost-estimate still has
|
||||
// no result, there is nothing further to render.
|
||||
if ce.Status != tfe.CostEstimateFinished {
|
||||
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
switch ce.Status {
|
||||
case tfe.CostEstimateFinished:
|
||||
delta, err := strconv.ParseFloat(ce.DeltaMonthlyCost, 64)
|
||||
|
@ -324,6 +332,8 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope
|
|||
b.CLI.Output("\n------------------------------------------------------------------------\n")
|
||||
}
|
||||
for i, pc := range r.PolicyChecks {
|
||||
// Read the policy check logs. This is a blocking call that will only
|
||||
// return once the policy check is complete.
|
||||
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
|
||||
if err != nil {
|
||||
return generalError("Failed to retrieve policy check logs", err)
|
||||
|
@ -336,6 +346,15 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope
|
|||
return generalError("Failed to retrieve policy check", err)
|
||||
}
|
||||
|
||||
// If the run is canceled or errored, but the policy check still has
|
||||
// no result, there is nothing further to render.
|
||||
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
|
||||
switch pc.Status {
|
||||
case tfe.PolicyPending, tfe.PolicyQueued, tfe.PolicyUnreachable:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
var msgPrefix string
|
||||
switch pc.Scope {
|
||||
case tfe.PolicyScopeOrganization:
|
||||
|
|
|
@ -308,12 +308,11 @@ in order to capture the filesystem context the remote workspace expects:
|
|||
return r, generalError("Failed to retrieve run", err)
|
||||
}
|
||||
|
||||
// Return if the run is canceled or errored. We return without
|
||||
// an error, even if the run errored, as the error is already
|
||||
// displayed by the output of the remote run.
|
||||
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
|
||||
return r, nil
|
||||
}
|
||||
// If the run is canceled or errored, we still continue to the
|
||||
// cost-estimation and policy check phases to ensure we render any
|
||||
// results available. In the case of a hard-failed policy check, the
|
||||
// status of the run will be "errored", but there is still policy
|
||||
// information which should be shown.
|
||||
|
||||
// Show any cost estimation output.
|
||||
if r.CostEstimate != nil {
|
||||
|
|
Loading…
Reference in New Issue