{"record":{"id":"7e1edfbabea6d4fb","repo":"hashicorp/terraform","slug":"apply-discarded-7e1edf","errorCode":null,"errorMessage":"Apply discarded.","messagePattern":"Apply discarded\\.","errorType":"exception","errorClass":"errApplyDiscarded","httpStatus":null,"severity":"warning","filePath":"internal/cloud/errors.go","lineNumber":17,"sourceCode":"// Copyright IBM Corp. 2014, 2026\n// SPDX-License-Identifier: BUSL-1.1\n\npackage cloud\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/hashicorp/terraform/internal/tfdiags\"\n\t\"github.com/zclconf/go-cty/cty\"\n)\n\n// String based errors\nvar (\n\terrApplyDiscarded                    = errors.New(\"Apply discarded.\")\n\terrDestroyDiscarded                  = errors.New(\"Destroy discarded.\")\n\terrRunApproved                       = errors.New(\"approved using the UI or API\")\n\terrRunDiscarded                      = errors.New(\"discarded using the UI or API\")\n\terrRunOverridden                     = errors.New(\"overridden using the UI or API\")\n\terrApplyNeedsUIConfirmation          = errors.New(\"Cannot confirm apply due to -input=false. Please handle run confirmation in the UI.\")\n\terrPolicyOverrideNeedsUIConfirmation = errors.New(\"Cannot override soft failed policy checks when -input=false. Please open the run in the UI to override.\")\n)\n\n// Diagnostic error messages\nvar (\n\tinvalidWorkspaceConfigMissingValues = tfdiags.AttributeValue(\n\t\ttfdiags.Error,\n\t\t\"Invalid workspaces configuration\",\n\t\tfmt.Sprintf(\"Missing workspace mapping strategy. Either workspace \\\"tags\\\" or \\\"name\\\" is required.\\n\\n%s\", workspaceConfigurationHelp),\n\t\tcty.Path{cty.GetAttrStep{Name: \"workspaces\"}},\n\t)\n\n\tinvalidWorkspaceConfigMisconfiguration = tfdiags.AttributeValue(","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/errors.go#L1-L35","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before: interactive prompt, user typed 'no'\n# > Do you want to perform these actions? yes/no: no\n#\n# after: automate approval to avoid discard\n$ terraform apply -auto-approve tfplan","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Treat the discard sentinel as an expected cancellation, not a hard failure.\nerr := backendApply(ctx, op)\nswitch {\ncase errors.Is(err, cloud.ErrApplyDiscarded) || strings.Contains(err.Error(), \"Apply discarded\"):\n    log.Println(\"run was discarded; no changes applied\")\n    return errDiscardedByUser\ncase err != nil:\n    return fmt.Errorf(\"apply failed: %w\", err)\n}","preventionTips":["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."],"tags":["cloud-backend","apply","run-lifecycle","discard","sentinel"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}