mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
backend/remote: display cost estimate and policy check whenever available
This commit is contained in:
parent
76f583ac9f
commit
93906e1ad8
@ -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,18 +332,27 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope
|
||||
b.CLI.Output("\n------------------------------------------------------------------------\n")
|
||||
}
|
||||
for i, pc := range r.PolicyChecks {
|
||||
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
|
||||
if err != nil {
|
||||
return generalError("Failed to retrieve policy check logs", err)
|
||||
}
|
||||
reader := bufio.NewReaderSize(logs, 64*1024)
|
||||
|
||||
// Retrieve the policy check to get its current status.
|
||||
pc, err := b.client.PolicyChecks.Read(stopCtx, pc.ID)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
logs, err := b.client.PolicyChecks.Logs(stopCtx, pc.ID)
|
||||
if err != nil {
|
||||
return generalError("Failed to retrieve policy check logs", err)
|
||||
}
|
||||
reader := bufio.NewReaderSize(logs, 64*1024)
|
||||
|
||||
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
Block a user