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)
|
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 {
|
switch ce.Status {
|
||||||
case tfe.CostEstimateFinished:
|
case tfe.CostEstimateFinished:
|
||||||
delta, err := strconv.ParseFloat(ce.DeltaMonthlyCost, 64)
|
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")
|
b.CLI.Output("\n------------------------------------------------------------------------\n")
|
||||||
}
|
}
|
||||||
for i, pc := range r.PolicyChecks {
|
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)
|
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generalError("Failed to retrieve policy check logs", err)
|
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)
|
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
|
var msgPrefix string
|
||||||
switch pc.Scope {
|
switch pc.Scope {
|
||||||
case tfe.PolicyScopeOrganization:
|
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 r, generalError("Failed to retrieve run", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if the run is canceled or errored. We return without
|
// If the run is canceled or errored, we still continue to the
|
||||||
// an error, even if the run errored, as the error is already
|
// cost-estimation and policy check phases to ensure we render any
|
||||||
// displayed by the output of the remote run.
|
// results available. In the case of a hard-failed policy check, the
|
||||||
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
|
// status of the run will be "errored", but there is still policy
|
||||||
return r, nil
|
// information which should be shown.
|
||||||
}
|
|
||||||
|
|
||||||
// Show any cost estimation output.
|
// Show any cost estimation output.
|
||||||
if r.CostEstimate != nil {
|
if r.CostEstimate != nil {
|
||||||
|
|
Loading…
Reference in New Issue