{"record":{"id":"936c96bebd59a6b0","repo":"hashicorp/terraform","slug":"missing-state-name-936c96","errorCode":null,"errorMessage":"missing state name","messagePattern":"missing state name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/s3/backend_state.go","lineNumber":158,"sourceCode":"\n\tif name == backend.DefaultStateName || name == \"\" {\n\t\treturn diags.Append(fmt.Errorf(\"can't delete default state\"))\n\t}\n\n\tlog.Info(\"Deleting workspace\")\n\n\tclient, err := b.remoteClient(name)\n\tif err != nil {\n\t\treturn diags.Append(err)\n\t}\n\n\treturn diags.Append(client.Delete())\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\tclient := &RemoteClient{\n\t\ts3Client:              b.s3Client,\n\t\tdynClient:             b.dynClient,\n\t\tbucketName:            b.bucketName,\n\t\tpath:                  b.path(name),\n\t\tserverSideEncryption:  b.serverSideEncryption,\n\t\tcustomerEncryptionKey: b.customerEncryptionKey,\n\t\tacl:                   b.acl,\n\t\tkmsKeyID:              b.kmsKeyID,\n\t\tddbTable:              b.ddbTable,\n\t\tskipS3Checksum:        b.skipS3Checksum,\n\t\tlockFilePath:          b.getLockFilePath(name),\n\t\tuseLockFile:           b.useLockFile,\n\t}\n\n\treturn client, nil","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/s3/backend_state.go#L140-L176","documentation":"Returned by (*Backend).remoteClient (internal/backend/remote-state/s3/backend_state.go:158) when the workspace name passed in is empty. remoteClient builds the S3 object key path (and DynamoDB lock path) from the workspace; an empty name would produce a malformed key. The guard fails fast before any AWS API call.","triggerScenarios":"Calling StateMgr(\"\") or DeleteWorkspace(\"\", _) on the s3 backend; CLI/wrapper code forwarding an unresolved (empty) workspace; automation reading the workspace from an unset env var.","commonSituations":"CI with a missing TF_WORKSPACE; migration tooling that doesn't resolve the current workspace; wrapper code that defaults to the zero value instead of \"default\"; programmatic use of the S3 backend without selecting a workspace.","solutions":["Resolve the workspace name to a non-empty value before calling StateMgr/DeleteWorkspace.","Default to backend.DefaultStateName when no workspace is explicitly selected.","Validate at the call site and surface a clear error to the caller."],"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 S3 backend.","Ensure TF_WORKSPACE is set explicitly in CI.","Validate workspace resolution at a single point in your tooling."],"tags":["backend","s3","aws","workspace","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}