{"record":{"id":"a04cf0ff3710567a","repo":"hashicorp/terraform","slug":"discarded-using-the-ui-or-api-a04cf0","errorCode":null,"errorMessage":"discarded using the UI or API","messagePattern":"discarded using the UI or API","errorType":"exception","errorClass":"errRunDiscarded","httpStatus":null,"severity":"warning","filePath":"internal/cloud/errors.go","lineNumber":20,"sourceCode":"// 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(\n\t\ttfdiags.Error,\n\t\t\"Invalid workspaces configuration\",\n\t\tfmt.Sprintf(\"Only one of workspace \\\"tags\\\" or \\\"name\\\" is allowed.\\n\\n%s\", workspaceConfigurationHelp),","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/errors.go#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// errRunDiscarded means an out-of-band discard; surface as cancellation.\nerr := b.confirm(ctx, op, opts, run, \"yes\")\nif err != nil && (errors.Is(err, cloud.ErrRunDiscarded) || strings.Contains(err.Error(), \"discarded using the UI or API\")) {\n    return errRunCancelled\n}","preventionTips":["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."],"tags":["cloud-backend","run-lifecycle","discard","sentinel"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}