{"record":{"id":"fda17015f2ac2dfc","repo":"hashicorp/terraform","slug":"error-loading-workspace-w-fda170","errorCode":null,"errorMessage":"error loading workspace: %w","messagePattern":"error loading workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend_context.go","lineNumber":196,"sourceCode":"\t}\n\n\treturn remoteWorkspace.ID, nil\n}\n\n// FetchVariables implements backendrun.ConstVariableSupplier by retrieving\n// Terraform variables from the HCP Terraform or Terraform Enterprise workspace.\nfunc (b *Cloud) FetchVariables(ctx context.Context, workspace string) (map[string]arguments.UnparsedVariableValue, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tremoteWorkspaceID, err := b.getRemoteWorkspaceID(ctx, workspace)\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"error finding remote workspace: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\tw, err := b.fetchWorkspace(ctx, b.Organization, workspace)\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"error loading workspace: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\tif isLocalExecutionMode(w.ExecutionMode) {\n\t\tlog.Printf(\"[TRACE] cloud: skipping variable fetch for workspace %s/%s (%s), workspace is in Local Execution mode\", b.getRemoteWorkspaceName(workspace), b.Organization, remoteWorkspaceID)\n\t\treturn nil, nil\n\t}\n\n\tlog.Printf(\"[TRACE] cloud: retrieving variables from workspace %s/%s (%s)\", b.getRemoteWorkspaceName(workspace), b.Organization, remoteWorkspaceID)\n\ttfeVariables, err := b.client.Variables.ListAll(ctx, remoteWorkspaceID, nil)\n\tif err != nil && err != tfe.ErrResourceNotFound {\n\t\tdiags = diags.Append(fmt.Errorf(\"error loading variables: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\tresult := make(map[string]arguments.UnparsedVariableValue)\n\tif tfeVariables != nil {\n\t\tfor _, v := range tfeVariables.Items {","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend_context.go#L178-L214","documentation":"In FetchVariables (backend_context.go:194-198), after getRemoteWorkspaceID succeeded, a SECOND workspace fetch via b.fetchWorkspace(ctx, b.Organization, workspace) failed. Note getRemoteWorkspaceID already read the workspace; this duplicate read can fail independently (e.g. race, or a 404/permissions path that fetchWorkspace re-wraps with the verbose 'workspace not found' message).","triggerScenarios":"b.fetchWorkspace at backend_context.go:194 returns an error. Because fetchWorkspace (backend.go:1328) maps ErrResourceNotFound to the verbose 484-style message and everything else to the 485-style message, this surfaces one of those wrapped forms inside 'error loading workspace'.","commonSituations":"Transient inconsistency or race where the workspace became inaccessible between the two reads. Permissions changed mid-operation. The same root causes as errors 484/485 (name/access/auth/network) but manifest during variable loading specifically.","solutions":["Treat the inner error like 484/485: check workspace name/access (404) or auth/network (other).","Retry; if it was a transient race the second read may succeed.","Verify the token's permissions haven't changed during the operation.","Ensure no concurrent workspace rename/delete is happening."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Re-fetch workspace once on transient failure during variable load.\nw, err := b.fetchWorkspace(ctx, org, ws)\nif err != nil && isTransient(err) {\n    time.Sleep(backoff); w, err = b.fetchWorkspace(ctx, org, ws)\n}","preventionTips":["Avoid concurrent rename/delete of the workspace during runs.","Ensure permissions are stable across the operation lifecycle.","Retry transient mid-operation workspace read failures."],"tags":["terraform","tfe","workspace","variables","cloud-backend","concurrency"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}