{"record":{"id":"39d818c854d10501","repo":"hashicorp/terraform","slug":"error-loading-variables-w","errorCode":null,"errorMessage":"error loading variables: %w","messagePattern":"error loading variables: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote/backend_context.go","lineNumber":118,"sourceCode":"\t\tremoteWorkspaceID, err := b.getRemoteWorkspaceID(context.Background(), op.Workspace)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"error finding remote workspace: %w\", err))\n\t\t\treturn nil, nil, diags\n\t\t}\n\n\t\tw, err := b.fetchWorkspace(context.Background(), b.organization, op.Workspace)\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"error loading workspace: %w\", err))\n\t\t\treturn nil, nil, diags\n\t\t}\n\n\t\tif isLocalExecutionMode(w.ExecutionMode) {\n\t\t\tlog.Printf(\"[TRACE] skipping retrieving variables from workspace %s/%s (%s), workspace is in Local Execution mode\", remoteWorkspaceName, b.organization, remoteWorkspaceID)\n\t\t} else {\n\t\t\tlog.Printf(\"[TRACE] backend/remote: retrieving variables from workspace %s/%s (%s)\", remoteWorkspaceName, b.organization, remoteWorkspaceID)\n\t\t\ttfeVariables, err := b.client.Variables.ListAll(context.Background(), remoteWorkspaceID, nil)\n\t\t\tif err != nil && err != tfe.ErrResourceNotFound {\n\t\t\t\tdiags = diags.Append(fmt.Errorf(\"error loading variables: %w\", err))\n\t\t\t\treturn nil, nil, diags\n\t\t\t}\n\t\t\tif tfeVariables != nil {\n\t\t\t\tif op.Variables == nil {\n\t\t\t\t\top.Variables = make(map[string]arguments.UnparsedVariableValue)\n\t\t\t\t}\n\t\t\t\tfor _, v := range tfeVariables.Items {\n\t\t\t\t\tif v.Category == tfe.CategoryTerraform {\n\t\t\t\t\t\tif _, ok := op.Variables[v.Key]; !ok {\n\t\t\t\t\t\t\top.Variables[v.Key] = &remoteStoredVariableValue{\n\t\t\t\t\t\t\t\tdefinition: v,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote/backend_context.go#L100-L136","documentation":"In LocalRun(), b.client.Variables.ListAll(remoteWorkspaceID, nil) returned an error that is not tfe.ErrResourceNotFound. The code explicitly tolerates a 404 (older TFE without the variables endpoint) but any other failure — auth, network, server error — surfaces as 'error loading variables'. Only reached for non-local-execution workspaces.","triggerScenarios":"LocalRun() lists workspace variables to inject them into a local plan/apply; ListAll fails with a non-404 error: token lacks variable-read permission, 5xx, network failure, or the variables API rejected the call.","commonSituations":"Token's team lacks 'Read Variables' permission on the workspace; transient API error; self-hosted TFE with a variables-service issue; the workspace has many variables and pagination/timeout occurs.","solutions":["Grant the token's team 'Read Variables' (or broader) permission on the workspace.","Retry on transient failures; unwrap %w to inspect the status.","If variables aren't required for this local operation, consider stubbing (AllowUnsetVariables) to skip this path."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify variable-read permission before listing.\nfunc canReadVars(w *tfe.Workspace) bool {\n    return w != nil && w.Permissions != nil && w.Permissions.CanReadVariable\n}","typeGuard":"func isNotFound(err error) bool { return errors.Is(err, tfe.ErrResourceNotFound) }","tryCatchPattern":"vars, err := b.client.Variables.ListAll(ctx, id, nil)\nif err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {\n    return fmt.Errorf(\"error loading variables: %w\", err)\n}","preventionTips":["Grant the token's team 'Read Variables' permission on the workspace.","Retry transient variable-API failures; unwrap %w for the status.","Use the AllowUnsetVariables path when variables aren't needed for a local op."],"tags":["variables","permissions","local-run","tfe-api"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}