{"record":{"id":"698f1dffbf1ba0f7","repo":"hashicorp/terraform","slug":"error-finding-remote-workspace-w-698f1d","errorCode":null,"errorMessage":"error finding remote workspace: %w","messagePattern":"error finding remote workspace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend_context.go","lineNumber":190,"sourceCode":"}\n\nfunc (b *Cloud) getRemoteWorkspaceID(ctx context.Context, localWorkspaceName string) (string, error) {\n\tremoteWorkspace, err := b.getRemoteWorkspace(ctx, localWorkspaceName)\n\tif err != nil {\n\t\treturn \"\", err\n\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))","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/backend_context.go#L172-L208","documentation":"FetchVariables (the ConstVariableSupplier hook) first resolves the remote workspace ID via getRemoteWorkspaceID; any failure there is wrapped as 'error finding remote workspace' before variable fetch is even attempted. This blocks variable auto-injection from the cloud workspace when the workspace cannot be located.","triggerScenarios":"b.getRemoteWorkspaceID(ctx, workspace) returns err: workspace name does not resolve in the org; API/transport failure during the ID lookup; permission denied on the workspace lookup. Distinct from the subsequent fetchWorkspace call which has its own error message.","commonSituations":"Variable auto-loading is enabled but the workspace name is wrong or the workspace was renamed; transient API failure during variable resolution; token lacks read on the workspace at variable-load time.","solutions":["Verify the workspace name and that getRemoteWorkspaceName resolves to a real workspace.","Re-run `terraform init` to refresh workspace metadata.","Confirm the token has read access on the workspace (and its variables).","Retry on transient failures; for permanent rename, update the cloud block."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func workspaceResolvable(client *tfe.Client, org, ws string) error {\n    if _, err := client.Workspaces.Read(ctx, org, ws); err != nil {\n        return fmt.Errorf(\"workspace %s/%s unresolvable for variable fetch: %w\", org, ws, err)\n    }\n    return nil\n}\n// run before FetchVariables is invoked","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the workspace name in the cloud block stable; avoid renames mid-pipeline.","Re-run `terraform init` after workspace renames.","Ensure the token has variable-read permission on the workspace.","Retry transient API failures during variable resolution."],"tags":["tfe","hcp","cloud-backend","workspace","variables"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}