{"record":{"id":"5df6dc458dddb923","repo":"hashicorp/terraform","slug":"error-starting-operation-s","errorCode":null,"errorMessage":"error starting operation: %s","messagePattern":"error starting operation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta.go","lineNumber":503,"sourceCode":"// until that operation completes or is interrupted, and then returns\n// the RunningOperation object representing the completed or\n// aborted operation that is, despite the name, no longer running.\n//\n// An error is returned if the operation either fails to start or is cancelled.\n// If the operation runs to completion then no error is returned even if the\n// operation itself is unsuccessful. Use the \"Result\" field of the\n// returned operation object to recognize operation-level failure.\nfunc (m *Meta) RunOperation(b backendrun.OperationsBackend, opReq *backendrun.Operation) (*backendrun.RunningOperation, error) {\n\tif opReq.View == nil {\n\t\tpanic(\"RunOperation called with nil View\")\n\t}\n\tif opReq.ConfigDir != \"\" {\n\t\topReq.ConfigDir = m.normalizePath(opReq.ConfigDir)\n\t}\n\n\top, err := b.Operation(m.CommandContext(), opReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error starting operation: %s\", err)\n\t}\n\n\t// Wait for the operation to complete or an interrupt to occur\n\tselect {\n\tcase <-m.ShutdownCh:\n\t\t// gracefully stop the operation\n\t\top.Stop()\n\n\t\t// Notify the user\n\t\topReq.View.Interrupted()\n\n\t\t// Still get the result, since there is still one\n\t\tselect {\n\t\tcase <-m.ShutdownCh:\n\t\t\topReq.View.FatalInterrupt()\n\n\t\t\t// cancel the operation completely\n\t\t\top.Cancel()","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta.go#L485-L521","documentation":"Returned by `Meta.RunOperation` when the backend's `Operation(ctx, opReq)` factory itself fails before any operation can run. This is distinct from an operation that starts but later fails (those surface via the `RunningOperation.Result` channel). The backend implementation refused to create the operation machinery — typically a configuration or precondition problem inside the backend.","triggerScenarios":"`b.Operation` returns `(nil, err)` because the backend cannot initialize an operation runner — e.g. a local backend with an invalid state lock, a remote/cloud backend whose configuration is incomplete, or a backend that requires a workspace that is not selected. `RunOperation` wraps the error and returns immediately.","commonSituations":"Cloud/remote backend `workspaces.name` or `workspaces.tags` misconfiguration; backend init was skipped (`terraform init` not run after a backend change); a stale or corrupted local state lock file; concurrent `terraform apply` on the same workspace holding a lock; backend credentials expired between init and the operation.","solutions":["Run `terraform init` to re-initialize the backend and validate its configuration.","Inspect the wrapped `%s` detail — it usually names the specific backend precondition that failed.","For cloud backends, confirm `workspaces.{name,tags,project}` in the `cloud` block matches existing HCP Terraform workspaces.","Clear a stale lock only if you are certain no other run is active: `terraform force-unlock <lock-id>`.","Re-authenticate if the backend credential has expired (`terraform login`)."],"exampleFix":"// before: backend misconfiguration\nbackend \"remote\" { organization = \"acme\" workspaces { name = \"\" } }\n// after\ncloud { organization = \"acme\" workspaces { name = \"prod\" } }\n# then\nterraform init\nterraform apply","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"// Wrap RunOperation; distinguish start-failure from operation-result failure.\nop, err := m.RunOperation(b, opReq)\nif err != nil {\n    // operation never started — backend/config issue, fix via init\n    return err\n}\nresult := <-op.Result\nif result.State == nil { /* operation ran but failed separately */ }","preventionTips":["Always run `terraform init` after changing backend configuration.","Validate `cloud`/`remote` workspace mapping before running operations.","In CI, run `terraform init -lockfile=readonly` then the operation to catch backend issues early."],"tags":["terraform","backend","operation","init","cli"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}