{"record":{"id":"63dbbe11e3240c77","repo":"hashicorp/terraform","slug":"error-getting-bucket-v","errorCode":null,"errorMessage":"error getting bucket: %#v","messagePattern":"error getting bucket: %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend_state.go","lineNumber":61,"sourceCode":"\t}\n\tif b.otsEndpoint != \"\" && b.otsTable != \"\" {\n\t\t_, err := b.otsClient.DescribeTable(&tablestore.DescribeTableRequest{\n\t\t\tTableName: b.otsTable,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn client, fmt.Errorf(\"error describing table store %s: %#v\", b.otsTable, err)\n\t\t}\n\t}\n\n\treturn client, nil\n}\n\nfunc (b *Backend) Workspaces() ([]string, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tbucket, err := b.ossClient.Bucket(b.bucketName)\n\tif err != nil {\n\t\treturn []string{\"\"}, diags.Append(fmt.Errorf(\"error getting bucket: %#v\", err))\n\t}\n\n\tvar options []oss.Option\n\toptions = append(options, oss.Prefix(b.statePrefix+\"/\"), oss.MaxKeys(1000))\n\tresp, err := bucket.ListObjects(options...)\n\tif err != nil {\n\t\treturn nil, diags.Append(err)\n\t}\n\n\tresult := []string{backend.DefaultStateName}\n\tprefix := b.statePrefix\n\tlastObj := \"\"\n\tfor {\n\t\tfor _, obj := range resp.Objects {\n\t\t\t// we have 3 parts, the state prefix, the workspace name, and the state file: <prefix>/<worksapce-name>/<key>\n\t\t\tif path.Join(b.statePrefix, b.stateKey) == obj.Key {\n\t\t\t\t// filter the default workspace\n\t\t\t\tcontinue","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oss/backend_state.go#L43-L79","documentation":"In Workspaces() (backend_state.go:59-61), b.ossClient.Bucket(b.bucketName) returned an error. The OSS SDK Bucket() is a local constructor that validates the bucket name; it fails before any network call when the name is malformed. This surfaces during workspace listing (terraform workspace list / StateMgr setup).","triggerScenarios":"ossClient.Bucket(b.bucketName) returns a non-nil error because bucketName violates OSS naming rules (uppercase letters, underscores, wrong length, invalid characters). Bucket() is a pure validation, so this is not a network/permissions problem.","commonSituations":"Bucket name contains uppercase (e.g. TfState), underscores, is shorter than 3 or longer than 63 chars, starts/ends with a dash, or includes forbidden characters; bucket variable interpolated incorrectly producing an empty/garbage value.","solutions":["Rename the bucket to a valid OSS name: lowercase letters, digits, hyphens only, 3-63 chars, no consecutive dots.","Check the variable/locals feeding the bucket attribute for interpolation mistakes (trailing slash, empty string).","Confirm the bucket value is not being read from a stale .tfvars or environment override."],"exampleFix":"// before\nbackend \"oss\" {\n  bucket = \"Terraform_State\"  // invalid\n}\n\n// after\nbackend \"oss\" {\n  bucket = \"terraform-state\"  // valid\n}","handlingStrategy":"validation","validationCode":"// Validate OSS bucket name locally before init.\nvar ossBucketRe = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$`)\n\nfunc validBucketName(name string) bool {\n    if !ossBucketRe.MatchString(name) || strings.Contains(name, \"--\") {\n        return false\n    }\n    return len(name) >= 3 && len(name) <= 63\n}","typeGuard":null,"tryCatchPattern":"// Pure validation error; not retryable. Fix the name and re-init.\nif !validBucketName(bucket) {\n    return fmt.Errorf(\"invalid OSS bucket name %q\", bucket)\n}","preventionTips":["Normalize bucket names to lowercase-digits-hyphens at the source.","Add a CI lint that regex-checks the backend bucket attribute.","Avoid dynamic interpolation that can produce empty/uppercase values."],"tags":["alibaba-cloud","oss","bucket-validation","remote-state","go"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}