{"record":{"id":"fb0a5f5a81d1ae01","repo":"hashicorp/terraform","slug":"workspace-key-prefix-must-not-start-with-or","errorCode":null,"errorMessage":"workspace_key_prefix must not start with '/' or './'","messagePattern":"workspace_key_prefix must not start with '/' or '\\./'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend.go","lineNumber":161,"sourceCode":"\t\t\t\tDescription: \"A custom endpoint for the OSS API\",\n\t\t\t\tDefaultFunc: schema.MultiEnvDefaultFunc([]string{\"ALICLOUD_OSS_ENDPOINT\", \"ALIBABA_CLOUD_OSS_ENDPOINT\", \"OSS_ENDPOINT\"}, \"\"),\n\t\t\t},\n\n\t\t\t\"bucket\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tRequired:    true,\n\t\t\t\tDescription: \"The name of the OSS bucket\",\n\t\t\t},\n\n\t\t\t\"prefix\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"The directory where state files will be saved inside the bucket\",\n\t\t\t\tDefault:     \"env:\",\n\t\t\t\tValidateFunc: func(v interface{}, s string) ([]string, []error) {\n\t\t\t\t\tprefix := v.(string)\n\t\t\t\t\tif strings.HasPrefix(prefix, \"/\") || strings.HasPrefix(prefix, \"./\") {\n\t\t\t\t\t\treturn nil, []error{fmt.Errorf(\"workspace_key_prefix must not start with '/' or './'\")}\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, nil\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t\"key\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"The path of the state file inside the bucket\",\n\t\t\t\tValidateFunc: func(v interface{}, s string) ([]string, []error) {\n\t\t\t\t\tif strings.HasPrefix(v.(string), \"/\") || strings.HasSuffix(v.(string), \"/\") {\n\t\t\t\t\t\treturn nil, []error{fmt.Errorf(\"key can not start and end with '/'\")}\n\t\t\t\t\t}\n\t\t\t\t\treturn nil, nil\n\t\t\t\t},\n\t\t\t\tDefault: \"terraform.tfstate\",\n\t\t\t},\n\t\t\t\"tablestore_instance_name\": {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oss/backend.go#L143-L179","documentation":"Returned by the ValidateFunc of the prefix (workspace_key_prefix) attribute of the oss backend when the value starts with '/' or './'. The prefix forms the directory path under which state files are stored, and a leading slash/dot-slash would create ambiguous absolute-style keys in OSS.","triggerScenarios":"Configuring prefix = \"/terraform\" or prefix = \"./env\" (or via the prefix env var equivalent) in the terraform backend 'oss' block. The ValidateFunc runs at init/plan.","commonSituations":"Porting a config from the s3 backend where a leading slash was tolerated; using a path variable that includes a leading slash; copy-paste from file paths.","solutions":["Remove the leading '/' or './' from the prefix value (e.g. prefix = \"terraform\").","If you interpolate from a variable, trim the prefix: prefix = trim(var.state_prefix, \"/\").","Leave prefix unset to use the default \"env:\"."],"exampleFix":"# before\nprefix = \"/terraform-state\"\n\n# after\nprefix = \"terraform-state\"","handlingStrategy":"validation","validationCode":"func normalizePrefix(p string) (string, error) {\n    if strings.HasPrefix(p, \"/\") || strings.HasPrefix(p, \"./\") {\n        return \"\", fmt.Errorf(\"prefix must not start with '/' or './'\")\n    }\n    return p, nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain relative path segments for prefix.","trim() interpolated variables.","Leave unset to use 'env:'."],"tags":["oss","validation","config","path","backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}