{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend_context.go#L172-L208","documentation":"In FetchVariables (backend_context.go:188-191), getRemoteWorkspaceID -> getRemoteWorkspace -> Workspaces.Read failed. This is the variable-fetch entry point; the workspace lookup (by name) failed before variables could be listed. The error wraps whatever the Read returned (404, auth, network, etc.).","triggerScenarios":"b.getRemoteWorkspaceID(ctx, workspace) at backend_context.go:188 returns an error. The underlying Workspaces.Read (backend_context.go:166) failed for any reason (not just 404).","commonSituations":"Wrong workspace name / organization when fetching variables. Token lacks read access. Network or API error. Workspace deleted between plan and variable fetch.","solutions":["Verify the workspace name resolves in the HCP/TFE UI and matches the cloud block / TF_WORKSPACE.","Inspect the wrapped error to distinguish 404 (name/access) from 5xx/network (retry).","Ensure the token has Read access on the workspace.","Re-run after correcting the mapping or credentials."],"exampleFix":"// before: TF_WORKSPACE=app-prod (doesn't exist)\nexport TF_WORKSPACE=app-prod && terraform plan\n// -> error finding remote workspace: ...\n// after\nexport TF_WORKSPACE=app_prod","handlingStrategy":"validation","validationCode":"func workspaceReadable(ctx context.Context, c *tfe.Client, org, ws string) bool {\n    _, err := c.Workspaces.Read(ctx, org, ws)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"// Distinguish 404 (name/access) from network for variable fetch.\nerr := getRemoteWorkspaceID(ctx, ws)\nif errors.Is(err, tfe.ErrResourceNotFound) { return clearNameOrAccessError(err) }\nif isTransient(err) { return retry() }","preventionTips":["Validate TF_WORKSPACE / cloud block names resolve before running.","Use a pre-flight Workspaces.Read in CI pipelines.","Keep the token's team read access on all referenced workspaces."],"tags":["terraform","tfe","workspace","variables","cloud-backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}