hashicorp/terraform · warning · errApplyDiscarded
Apply discarded.
Error message
Apply discarded.
What it means
errApplyDiscarded is a sentinel returned by the cloud backend when a run that was awaiting apply confirmation is discarded instead of applied. It fires from the confirm() loop in backend_common.go when the run's status flips to RunDiscarded while the CLI is waiting for the user to type 'yes', or when the user types anything other than 'yes' (the backend then discards the run). It signals the apply was intentionally aborted, not that a system error occurred.
Source
Thrown at internal/cloud/errors.go:17
// Copyright IBM Corp. 2014, 2026
// 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(View on GitHub (pinned to c9def3e214)
Solutions
- Treat this as expected cancellation: re-run 'terraform apply' to create a fresh run if changes are still needed.
- If discarded by someone else, check the run history in the HCP Terraform UI to confirm intent before re-applying.
- For non-interactive pipelines, pass -auto-approve to skip the confirmation prompt entirely.
Example fix
# before: interactive prompt, user typed 'no' # > Do you want to perform these actions? yes/no: no # # after: automate approval to avoid discard $ terraform apply -auto-approve tfplan
Defensive patterns
Strategy: try-catch
Try / catch
// Treat the discard sentinel as an expected cancellation, not a hard failure.
err := backendApply(ctx, op)
switch {
case errors.Is(err, cloud.ErrApplyDiscarded) || strings.Contains(err.Error(), "Apply discarded"):
log.Println("run was discarded; no changes applied")
return errDiscardedByUser
case err != nil:
return fmt.Errorf("apply failed: %w", err)
} Prevention
- Use -auto-approve in CI to remove the interactive prompt that leads to discard.
- Coordinate so only one actor (CLI or UI) manages a run at a time.
- Map the discard sentinel to a distinct exit code in wrappers so callers can retry cleanly.
When it happens
Trigger: In Cloud.confirm (backend_common.go:490-491 and :547): when the polled run's Status becomes tfe.RunDiscarded, or the operator enters a non-'yes' answer causing Runs.Discard(); the returned error is rewritten to errApplyDiscarded (errDestroyDiscarded for destroy mode).
Common situations: User at the 'Do you want to perform these actions?' prompt answers 'no' or anything other than 'yes'; a teammate clicks Discard in the HCP Terraform UI while the CLI prompt is open; an API call discards the run mid-prompt.
Related errors
- approved using the UI or API
- discarded using the UI or API
- overridden using the UI or API
- Cannot confirm apply due to -input=false. Please handle run
- %s errored.
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/7e1edfbabea6d4fb.
Report an issue: GitHub.