hashicorp/terraform · warning · errRunDiscarded
discarded using the UI or API
Error message
discarded using the UI or API
What it means
errRunDiscarded is a sentinel returned by confirm() when the run's status becomes RunDiscarded while the CLI awaited input — i.e. the run was discarded externally through the UI or API rather than via the CLI prompt. It differs from errApplyDiscarded in that the discard originated out-of-band; errApplyDiscarded is the rewritten form surfaced to the apply caller.
Source
Thrown at internal/cloud/errors.go:20
// SPDX-License-Identifier: BUSL-1.1
package cloud
import (
"errors"
"fmt"
"strings"
"github.com/hashicorp/terraform/internal/tfdiags"
"github.com/zclconf/go-cty/cty"
)
// String based errors
var (
errApplyDiscarded = errors.New("Apply discarded.")
errDestroyDiscarded = errors.New("Destroy discarded.")
errRunApproved = errors.New("approved using the UI or API")
errRunDiscarded = errors.New("discarded using the UI or API")
errRunOverridden = errors.New("overridden using the UI or API")
errApplyNeedsUIConfirmation = errors.New("Cannot confirm apply due to -input=false. Please handle run confirmation in the UI.")
errPolicyOverrideNeedsUIConfirmation = errors.New("Cannot override soft failed policy checks when -input=false. Please open the run in the UI to override.")
)
// Diagnostic error messages
var (
invalidWorkspaceConfigMissingValues = tfdiags.AttributeValue(
tfdiags.Error,
"Invalid workspaces configuration",
fmt.Sprintf("Missing workspace mapping strategy. Either workspace \"tags\" or \"name\" is required.\n\n%s", workspaceConfigurationHelp),
cty.Path{cty.GetAttrStep{Name: "workspaces"}},
)
invalidWorkspaceConfigMisconfiguration = tfdiags.AttributeValue(
tfdiags.Error,
"Invalid workspaces configuration",
fmt.Sprintf("Only one of workspace \"tags\" or \"name\" is allowed.\n\n%s", workspaceConfigurationHelp),View on GitHub (pinned to c9def3e214)
Solutions
- Confirm the discard was intentional by checking the run history in the UI/API.
- Re-run 'terraform plan'/'apply' to produce a new run if the changes are still desired.
- Coordinate with team members to avoid concurrent manual and CLI-driven run management on the same workspace.
Defensive patterns
Strategy: try-catch
Try / catch
// errRunDiscarded means an out-of-band discard; surface as cancellation.
err := b.confirm(ctx, op, opts, run, "yes")
if err != nil && (errors.Is(err, cloud.ErrRunDiscarded) || strings.Contains(err.Error(), "discarded using the UI or API")) {
return errRunCancelled
} Prevention
- Lock concurrent run management to a single channel (CLI xor UI) per workspace.
- Surface discard events to stakeholders so a discard isn't mistaken for an apply.
- In CI, prefer -auto-approve or fully UI-driven flows, not both.
When it happens
Trigger: Cloud.confirm (backend_common.go:469,477): the poll loop sees Status == tfe.RunDiscarded and returns errRunDiscarded for both 'override' and 'yes' keywords; backend_common.go:490 then maps it to errApplyDiscarded for the apply path.
Common situations: A teammate discards the run in the HCP Terraform UI while you sit at the CLI confirmation prompt; an automation pipeline discards the run via API on a failed upstream check.
Related errors
- Apply discarded.
- approved using the UI or API
- overridden using the UI or API
- %s errored.
- %s hard failed.
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/a04cf0ff3710567a.
Report an issue: GitHub.