{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote/backend_context.go#L100-L136","documentation":"After the workspace is loaded, the backend calls Variables.ListAll to fetch Terraform-category variables for remote execution. ErrResourceNotFound is intentionally swallowed (a workspace with no variables is fine); any OTHER error is wrapped here. This path is skipped entirely for Local execution-mode workspaces, so it only fires for Remote execution mode.","triggerScenarios":"b.client.Variables.ListAll(ctx, remoteWorkspaceID, nil) returns an error that is NOT tfe.ErrResourceNotFound: 401/403 (token lacks read-vars scope), 429 rate limit, 5xx server error, or network failure mid-pagination.","commonSituations":"Team API token used for `terraform plan/apply` lacks permission to read workspace variables; TFC under load returning 429; transient API outage; the workspace was deleted between fetchWorkspace and ListAll.","solutions":["Ensure the token has at least 'Read Variables' permission on the workspace (team token or user token with appropriate team access).","Retry — 429/5xx from TFC are typically transient; add a short backoff.","If using a service-limited token, verify it is not scoped to a team that lacks variable access.","Check TFC status and the organization's API rate-limit usage."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Confirm token can list variables before plan\nvars, err := c.Variables.ListAll(ctx, wsID, nil)\nif err != nil && err != tfe.ErrResourceNotFound { return err }","typeGuard":null,"tryCatchPattern":"// Retry transient 429/5xx on Variables.ListAll\nvar v *tfe.VariableList\nerr := retryOnHTTP(5, func() error {\n    var e error\n    v, e = c.Variables.ListAll(ctx, wsID, nil)\n    if e == tfe.ErrResourceNotFound { e = nil }\n    return e\n})","preventionTips":["Grant the run token 'Read Variables' on the workspace.","Use workspace-scoped tokens rather than org-wide tokens to reduce blast radius.","Remember variables are only fetched for Remote execution-mode workspaces."],"tags":["terraform","remote-backend","tfe","variables","permissions","remote-execution"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}