Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/v1.16/BUG FIXES-20260728-043144.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'cloud: Fixed a bug causing the CLI to pause indefinitely after a run task failure with pending policy evaluations'
time: 2026-07-28T04:31:44.000000-07:00
custom:
Issue: "38751"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/hashicorp/go-plugin v1.7.0
github.com/hashicorp/go-retryablehttp v0.7.8
github.com/hashicorp/go-slug v0.18.1
github.com/hashicorp/go-tfe v1.108.0
github.com/hashicorp/go-tfe v1.110.0
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.9.0
github.com/hashicorp/hcl v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ github.com/hashicorp/go-slug v0.18.1 h1:UnWIy4mq9GaDr1LhAzCPgA6RSQUn952RLFqQe3HP
github.com/hashicorp/go-slug v0.18.1/go.mod h1:Zxkkl8/LfXmhxZO3fLXQUCy3MVXAJK9pybY8WoDPgvs=
github.com/hashicorp/go-sockaddr v1.0.5 h1:dvk7TIXCZpmfOlM+9mlcrWmWjw/wlKT+VDq2wMvfPJU=
github.com/hashicorp/go-sockaddr v1.0.5/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI=
github.com/hashicorp/go-tfe v1.108.0 h1:Wsy7Jj0NOfaHs83v+2h7QcTxsVR8svQaUFTZJ0xJSLk=
github.com/hashicorp/go-tfe v1.108.0/go.mod h1:d8js2OmMnCq58gEh26mCS81nD8Aj7HmG6IO1b80gM78=
github.com/hashicorp/go-tfe v1.110.0 h1:R61zw8hgXH+A06rb77GhZXkexjiTls/sPM+lL3G4VsE=
github.com/hashicorp/go-tfe v1.110.0/go.mod h1:VH4URSfSw6421VEBdfjub/oTINTvT5Mhp4Gd9IA3Ifw=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down
56 changes: 52 additions & 4 deletions internal/cloud/backend_taskStage_policyEvaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ type policyEvaluationSummary struct {
passed int
}

func isNonTerminalPolicyEvaluationStatus(status tfe.PolicyEvaluationStatus) bool {
switch status {
case tfe.PolicyEvaluationRunning, tfe.PolicyEvaluationPending, tfe.PolicyEvaluationQueued:
return true
default:
return false
}
}

func partitionPolicyEvaluations(policyEvaluations []*tfe.PolicyEvaluation) ([]*tfe.PolicyEvaluation, []*tfe.PolicyEvaluation) {
completed := make([]*tfe.PolicyEvaluation, 0, len(policyEvaluations))
pending := make([]*tfe.PolicyEvaluation, 0, len(policyEvaluations))
for _, policyEvaluation := range policyEvaluations {
if isNonTerminalPolicyEvaluationStatus(policyEvaluation.Status) {
pending = append(pending, policyEvaluation)
continue
}
completed = append(completed, policyEvaluation)
}

return completed, pending
}

type Symbol rune

const (
Expand Down Expand Up @@ -56,7 +79,7 @@ func (pes *policyEvaluationSummarizer) Summarize(context *IntegrationContext, ou

counts := summarizePolicyEvaluationResults(ts.PolicyEvaluations)

if counts.pending != 0 {
if counts.pending != 0 && !isTerminalTaskStageStatus(ts.Status) {
pendingMessage := "Evaluating ... "
return true, &pendingMessage, nil
}
Expand All @@ -68,7 +91,7 @@ func (pes *policyEvaluationSummarizer) Summarize(context *IntegrationContext, ou
}

// Print out the summary
if err := pes.taskStageWithPolicyEvaluation(context, output, ts.PolicyEvaluations); err != nil {
if err := pes.taskStageWithPolicyEvaluation(context, output, ts); err != nil {
return false, nil, err
}
// Mark as finished
Expand Down Expand Up @@ -103,10 +126,26 @@ func summarizePolicyEvaluationResults(policyEvaluations []*tfe.PolicyEvaluation)
}
}

func (pes *policyEvaluationSummarizer) taskStageWithPolicyEvaluation(context *IntegrationContext, output IntegrationOutputWriter, policyEvaluation []*tfe.PolicyEvaluation) error {
func (pes *policyEvaluationSummarizer) taskStageWithPolicyEvaluation(context *IntegrationContext, output IntegrationOutputWriter, ts *tfe.TaskStage) error {
policyEvaluations := ts.PolicyEvaluations
pendingToSkipCount := 0

if isTerminalTaskStageStatus(ts.Status) {
completed, pending := partitionPolicyEvaluations(policyEvaluations)
if len(pending) > 0 && len(completed) == 0 {
output.Output("Skipping policy evaluation.")
output.End()
return nil
}

if len(pending) > 0 {
pendingToSkipCount = len(pending)
}
}

var result, message, kind string
// Currently only one policy evaluation supported : OPA
for _, polEvaluation := range policyEvaluation {
for _, polEvaluation := range policyEvaluations {
if polEvaluation.PolicyKind == "opa" {
kind = "OPA"
} else {
Expand All @@ -118,6 +157,9 @@ func (pes *policyEvaluationSummarizer) taskStageWithPolicyEvaluation(context *In
if polEvaluation.ResultCount.AdvisoryFailed > 0 {
result += " (with advisory)"
}
} else if isNonTerminalPolicyEvaluationStatus(polEvaluation.Status) {
message = fmt.Sprintf("[dim] Pending policy evaluation skipped as task stage is %s.", ts.Status)
result = "[dim]skipped"
} else {
message = fmt.Sprintf("[dim] This result means that one or more %s policies failed. More than likely, this was due to the discovery of violations by the main rule and other sub rules", kind)
result = fmt.Sprintf("[red]%s", strings.ToUpper(string(tfe.PolicyEvaluationFailed)))
Expand Down Expand Up @@ -160,6 +202,12 @@ func (pes *policyEvaluationSummarizer) taskStageWithPolicyEvaluation(context *In
}
}
}

if pendingToSkipCount > 0 {
output.Output(fmt.Sprintf("Skipping %d pending policy evaluation(s) because task stage is %s.", pendingToSkipCount, ts.Status))
output.End()
}

return nil
}

Expand Down
Loading