{"record":{"id":"18e69fa96a869340","repo":"hashicorp/terraform","slug":"prefix-must-not-start-with-or","errorCode":null,"errorMessage":"prefix must not start with '/' or './'","messagePattern":"prefix must not start with '/' or '\\./'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/backend/remote-state/cos/backend.go","lineNumber":136,"sourceCode":"\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"The custom endpoint for the COS API, e.g. http://cos-internal.{Region}.tencentcos.cn. Both HTTP and HTTPS are accepted.\",\n\t\t\t\tDefaultFunc: schema.EnvDefaultFunc(PROVIDER_ENDPOINT, nil),\n\t\t\t},\n\t\t\t\"domain\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil),\n\t\t\t\tDescription: \"The root domain of the API request. Default is tencentcloudapi.com.\",\n\t\t\t},\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 for saving the state file in bucket\",\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(\"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\t\t\t\"key\": {\n\t\t\t\tType:        schema.TypeString,\n\t\t\t\tOptional:    true,\n\t\t\t\tDescription: \"The path for saving the state file in bucket\",\n\t\t\t\tDefault:     \"terraform.tfstate\",\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},\n\t\t\t\"encrypt\": {\n\t\t\t\tType:        schema.TypeBool,","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/cos/backend.go#L118-L154","documentation":"ValidateFunc for the cos backend's `prefix` attribute (cos/backend.go:136). Object-key prefixes in COS must be relative; a leading '/' or './' would produce malformed keys, so configuration validation rejects it before the backend is configured.","triggerScenarios":"Setting prefix = \"/env/state\" or prefix = \"./env/state\" in the backend block triggers the ValidateFunc which checks HasPrefix(\"/\") or HasPrefix(\"./\").","commonSituations":"Copying a local filesystem path that begins with '/' into the prefix; assuming prefix behaves like an absolute path; migrating from an S3 backend with a leading slash.","solutions":["Remove any leading '/' or './' from prefix, e.g. prefix = \"env/state\".","Treat prefix as a relative object key prefix, not a filesystem path.","Leave prefix unset if you want state at the bucket root."],"exampleFix":"// before\nterraform {\n  backend \"cos\" {\n    prefix = \"/terraform/prod\"\n  }\n}\n// after\nterraform {\n  backend \"cos\" {\n    prefix = \"terraform/prod\"\n  }\n}","handlingStrategy":"validation","validationCode":"// Validate the cos prefix before passing it to the backend\nfunc validPrefix(p string) error {\n    if strings.HasPrefix(p, \"/\") || strings.HasPrefix(p, \"./\") {\n        return fmt.Errorf(\"prefix must not start with '/' or './'\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat prefix as a relative object-key prefix, not a filesystem path.","Run `terraform init` early to surface validation errors before apply.","Strip leading slashes when migrating paths from other backends."],"tags":["cos","tencentcloud","validation","config","prefix"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}