hashicorp/terraform · error
missing state name
Error message
missing state name
What it means
Returned by (*Backend).remoteClient (internal/backend/remote-state/oss/backend_state.go:31) when the workspace name passed in is empty. remoteClient derives the OSS state file path (stateFile) and lock file path from the workspace, and an empty name would yield a malformed object key. The guard fails fast before any Alibaba Cloud OSS/OTS API call.
Source
Thrown at internal/backend/remote-state/oss/backend_state.go:31
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore"
"github.com/hashicorp/terraform/internal/backend"
"github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/states/remote"
"github.com/hashicorp/terraform/internal/states/statemgr"
"github.com/hashicorp/terraform/internal/tfdiags"
)
const (
lockFileSuffix = ".tflock"
)
// get a remote client configured for this state
func (b *Backend) remoteClient(name string) (*RemoteClient, error) {
if name == "" {
return nil, errors.New("missing state name")
}
client := &RemoteClient{
ossClient: b.ossClient,
bucketName: b.bucketName,
stateFile: b.stateFile(name),
lockFile: b.lockFile(name),
serverSideEncryption: b.serverSideEncryption,
acl: b.acl,
otsTable: b.otsTable,
otsClient: b.otsClient,
}
if b.otsEndpoint != "" && b.otsTable != "" {
_, err := b.otsClient.DescribeTable(&tablestore.DescribeTableRequest{
TableName: b.otsTable,
})
if err != nil {
return client, fmt.Errorf("error describing table store %s: %#v", b.otsTable, err)View on GitHub (pinned to c9def3e214)
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 return a descriptive error to the caller.
Example fix
// before
client, err := b.remoteClient(ws) // ws == ""
// after
if ws == "" {
ws = backend.DefaultStateName
}
client, err := b.remoteClient(ws) Defensive patterns
Strategy: validation
Validate before calling
if name == "" {
name = backend.DefaultStateName
}
client, err := b.remoteClient(name) Prevention
- Resolve the workspace to a non-empty value (default to "default") before invoking the OSS backend.
- Validate workspace env vars are set in CI before running terraform.
- Centralize workspace resolution so all backends receive a valid name.
When it happens
Trigger: Calling StateMgr("") or DeleteWorkspace("", _) on the oss backend; CLI/wrapper logic forwarding an unset workspace variable; automation reading the workspace from an unset TF_WORKSPACE.
Common situations: CI scripts with a missing/empty workspace env var; migration tooling that doesn't resolve the current workspace before invoking the backend; bugs in workspace resolution upstream of the OSS backend.
Related errors
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/3281dd8fdd967408.
Report an issue: GitHub.