{"record":{"id":"eab2119180c99329","repo":"hashicorp/terraform","slug":"error-loading-variables-w-eab211","errorCode":null,"errorMessage":"error loading variables: %w","messagePattern":"error loading variables: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend_context.go","lineNumber":208,"sourceCode":"\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 {\n\t\t\tif v.Category == tfe.CategoryTerraform {\n\t\t\t\tresult[v.Key] = &remoteStoredVariableValue{\n\t\t\t\t\tdefinition: v,\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result, nil\n}\n\n// remoteStoredVariableValue is a backendrun.UnparsedVariableValue implementation","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend_context.go#L190-L226","documentation":"In FetchVariables (backend_context.go:206-209), b.client.Variables.ListAll(ctx, remoteWorkspaceID, nil) failed with an error other than tfe.ErrResourceNotFound (404 is explicitly ignored so a workspace with no variables still works). This is the actual variable-list API call failing due to network, auth, server, or permission issues on the variables endpoint.","triggerScenarios":"Variables.ListAll at backend_context.go:206 returns err != nil && err != tfe.ErrResourceNotFound. Occurs when listing workspace Terraform variables fails for a non-'not found' reason.","commonSituations":"Token lacks permission to list variables on the workspace. Transient API/network error. TFE variables service degraded. Rate limiting. Workspace ID stale (workspace recreated) so the variables endpoint 500s.","solutions":["Grant the token's team permission to read workspace variables (or 'Manage Workspaces').","Retry for transient/network errors.","Inspect the wrapped error for HTTP status (403 => permissions, 5xx => server, 429 => rate limit).","Verify the workspace still exists and its ID is current (re-run init)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"func canListVariables(ctx context.Context, c *tfe.Client, wsID string) bool {\n    _, err := c.Variables.List(ctx, wsID, nil)\n    return err == nil || errors.Is(err, tfe.ErrResourceNotFound)\n}","typeGuard":null,"tryCatchPattern":"// Retry non-404 variable-list failures with backoff.\nfor i := 0; i < 3; i++ {\n    vars, err := c.Variables.ListAll(ctx, wsID, nil)\n    if err == nil || errors.Is(err, tfe.ErrResourceNotFound) { return vars }\n    if !isRetryable(err) { return err }\n    time.Sleep(backoff(i))\n}","preventionTips":["Grant the token read access to workspace variables.","Retry transient API errors with exponential backoff.","Inspect wrapped HTTP status to separate permissions (403) from server (5xx)."],"tags":["terraform","tfe","variables","api","permissions","cloud-backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}