{"record":{"id":"097493ea3be72230","repo":"hashicorp/terraform","slug":"missing-state-name","errorCode":null,"errorMessage":"missing state name","messagePattern":"missing state name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/kubernetes/backend_state.go","lineNumber":156,"sourceCode":"\t\tif err := stateMgr.PersistState(nil); err != nil {\n\t\t\tunlockErr := unlock(err)\n\t\t\treturn nil, diags.Append(unlockErr)\n\t\t}\n\n\t\t// Unlock, the state should now be initialized\n\t\tif err := unlock(nil); err != nil {\n\t\t\treturn nil, diags.Append(err)\n\t\t}\n\n\t}\n\n\treturn stateMgr, diags\n}\n\n// get a remote client configured for this state\nfunc (b *Backend) remoteClient(name string) (*RemoteClient, error) {\n\tif name == \"\" {\n\t\treturn nil, errors.New(\"missing state name\")\n\t}\n\n\tsecretClient, err := b.KubernetesSecretClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tleaseClient, err := b.KubernetesLeaseClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclient := &RemoteClient{\n\t\tkubernetesSecretClient: secretClient,\n\t\tkubernetesLeaseClient:  leaseClient,\n\t\tnamespace:              b.namespace,\n\t\tlabels:                 b.labels,\n\t\tnameSuffix:             b.nameSuffix,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/kubernetes/backend_state.go#L138-L174","documentation":"Returned by (*Backend).remoteClient (internal/backend/remote-state/kubernetes/backend_state.go:156) when the workspace name passed in is empty. remoteClient builds the secret name, labels, and lease name from the workspace, so an empty name would produce invalid Kubernetes resource names downstream. The guard fails fast before any k8s API call.","triggerScenarios":"Calling StateMgr(\"\"), DeleteWorkspace(\"\", _), or any path through remoteClient with an unresolved workspace; CLI/wrapper code that forwards an empty TF_WORKSPACE or current workspace to the kubernetes backend.","commonSituations":"Automation that reads the workspace from an unset env var; migrating configs where the workspace block is missing; bugs in workspace resolution that yield \"\" before the k8s backend is invoked.","solutions":["Ensure the workspace name is resolved to a non-empty value before calling StateMgr/DeleteWorkspace.","Default to backend.DefaultStateName (\"default\") when no workspace is selected.","Validate workspace name != \"\" at the call site and surface a clear upstream error."],"exampleFix":"// before\nclient, err := b.remoteClient(ws) // ws == \"\"\n\n// after\nif ws == \"\" {\n    ws = backend.DefaultStateName\n}\nclient, err := b.remoteClient(ws)","handlingStrategy":"validation","validationCode":"if name == \"\" {\n    name = backend.DefaultStateName\n}\nclient, err := b.remoteClient(name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve the workspace to a non-empty value (default to \"default\") before invoking the k8s backend.","Validate at a single chokepoint in your tooling so all backends receive a non-empty name.","Surface clear errors when workspace env vars are unset."],"tags":["backend","kubernetes","workspace","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}