{"record":{"id":"1351a1f37bca348b","repo":"hashicorp/terraform","slug":"key-can-not-start-and-end-with-1351a1","errorCode":null,"errorMessage":"key can not start and end with '/'","messagePattern":"key can not start and end with '/'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oss/backend.go","lineNumber":173,"sourceCode":"\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\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"The instance name of tableStore table belongs\",\n\t\t\t\tDefault:     \"\",\n\t\t\t},\n\n\t\t\t\"tablestore_table\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"TableStore table for state locking and consistency\",\n\t\t\t\tDefault:     \"\",\n\t\t\t},","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oss/backend.go#L155-L191","documentation":"Returned by the ValidateFunc of the key attribute of the oss backend when the state-file path starts or ends with '/'. A leading/trailing slash would resolve to a directory-like object key rather than the state file path; this validator blocks it at config time.","triggerScenarios":"Setting key = \"/terraform.tfstate\" or key = \"path/to/state/\" in the oss backend block, or supplying such a value via the key schema default override.","commonSituations":"Copy-pasting an S3 key that had a leading slash; treating key as a directory; trailing slash typo.","solutions":["Use a clean object path with no leading or trailing slash, e.g. key = \"terraform.tfstate\".","If you need subdirectories, separate with single slashes in the middle: key = \"prod/web/terraform.tfstate\".","Verify any interpolated variable does not add slashes."],"exampleFix":"# before\nkey = \"/env/prod/terraform.tfstate/\"\n\n# after\nkey = \"env/prod/terraform.tfstate\"","handlingStrategy":"validation","validationCode":"func validateStateKey(k string) error {\n    if strings.HasPrefix(k, \"/\") || strings.HasSuffix(k, \"/\") {\n        return fmt.Errorf(\"key must not start or end with '/'\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["End the key with a filename like terraform.tfstate.","Never prefix the key with '/'.","Use single slashes between intermediate dirs only."],"tags":["oss","validation","config","path","backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}