{"record":{"id":"414dd52ed655963f","repo":"hashicorp/terraform","slug":"errapplydiscarded","errorCode":"errApplyDiscarded","errorMessage":"Apply discarded.","messagePattern":"Apply discarded\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/errors.go#L1-L35","documentation":"Returned by the Terraform Cloud backend when an apply run is discarded before it executes. The discard can originate from the local confirmation prompt (user typed something other than 'yes') or from an external action via the TFC/TFE UI or API. It is a sentinel error defined in internal/cloud/errors.go and set in backend_common.go within the confirm() goroutine when run status becomes RunDiscarded or when the user declines confirmation.","triggerScenarios":"Running 'terraform apply' against a cloud-backed workspace, responding with anything other than 'yes' at the approval prompt, or having the run discarded externally (UI/API) while the CLI is waiting for interactive confirmation. backend_common.go:490-491 maps errRunDiscarded to errApplyDiscarded for non-destroy plan modes.","commonSituations":"A CI pipeline or operator aborts the apply by typing 'no'; another team member cancels the run in the Terraform Cloud UI while the CLI is still polling; an automation tool sends a Discard API call concurrently with a local apply.","solutions":["Re-run 'terraform apply' if the discard was unintentional.","If discarding was intentional, no action is needed — this is expected control flow, not a bug.","Coordinate with team members to avoid concurrent UI/API and CLI operations on the same workspace.","Use -auto-approve to bypass interactive confirmation if you want unattended applies."],"exampleFix":"// before: interactive apply that gets discarded\nterraform apply\n// user types 'no' -> Apply discarded.\n\n// after: auto-approve to avoid discard-by-prompt\nterraform apply -auto-approve","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In Go code wrapping terraform CLI execution:\n// if errors.Is(err, cloud.ErrApplyDiscarded) {\n//     log.Info(\"apply was discarded, not a failure\")\n//     return nil // treat as non-error in automation\n// }","preventionTips":["Use -auto-approve in CI/CD to avoid interactive prompts that lead to discards.","Coordinate with team members to prevent concurrent UI/API discard operations during CLI sessions.","Treat exit codes from terraform apply carefully — a discarded apply is not always a pipeline failure."],"tags":["terraform","cloud","apply","run-lifecycle","confirmation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}