{"record":{"id":"0e5992e3223438c1","repo":"hashicorp/terraform","slug":"too-many-command-line-arguments-did-you-mean-to-u-0e5992","errorCode":null,"errorMessage":"Too many command line arguments. Did you mean to use -chdir?","messagePattern":"Too many command line arguments\\. Did you mean to use -chdir\\?","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/command.go","lineNumber":66,"sourceCode":"The \"backend\" in Terraform defines how Terraform operates. The default\nbackend performs all operations locally on your machine. Your configuration\nis configured to use a non-local backend. This backend doesn't support this\noperation.\n`\n\n// ModulePath returns the path to the root module and validates CLI arguments.\n//\n// This centralizes the logic for any commands that previously accepted\n// a module path via CLI arguments. This will error if any extraneous arguments\n// are given and suggest using the -chdir flag instead.\n//\n// If your command accepts more than one arg, then change the slice bounds\n// to pass validation.\nfunc ModulePath(args []string) (string, error) {\n\t// TODO: test\n\n\tif len(args) > 0 {\n\t\treturn \"\", fmt.Errorf(\"Too many command line arguments. Did you mean to use -chdir?\")\n\t}\n\n\tpath, err := os.Getwd()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error getting pwd: %s\", err)\n\t}\n\n\treturn path, nil\n}\n","sourceCodeStart":48,"sourceCodeEnd":76,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/command.go#L48-L76","documentation":"Thrown by command.ModulePath when args is non-empty. ModulePath is the shared validator for commands that historically accepted a module-path positional argument but now expect module selection via the global -chdir flag. Any extra positional argument trips this guard before os.Getwd is called.","triggerScenarios":"Running a command (e.g. validate, fmt in some flows, init with a stray path) and passing a positional path argument instead of using -chdir. Example: `terraform validate ./my-module` instead of `terraform -chdir=./my-module validate`.","commonSituations":"Users upgrading from older Terraform where positional module paths were accepted; copy-pasting examples that pre-date -chdir; muscle memory of passing `.` as a final arg.","solutions":["Remove the positional path and use the global -chdir flag placed before the subcommand.","If your command legitimately takes extra args, change the slice bounds passed to ModulePath (per the doc comment) or use a different code path.","Check the command's help (`terraform <cmd> -help`) for accepted arguments."],"exampleFix":"// before\n//   terraform validate ./infra\n// after\n//   terraform -chdir=./infra validate","handlingStrategy":"validation","validationCode":"// For commands that take no positional args, validate before invoking Terraform\nfunc validateNoPositional(args []string) error {\n    if len(args) > 0 {\n        return fmt.Errorf(\"use -chdir=%s instead of a positional path\", args[0])\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `-chdir=<path>` (before the subcommand) for module selection.","Read each command's -help to know which positional args are accepted.","Wrap Terraform in scripts that translate legacy positional paths to -chdir."],"tags":["cli","arguments","chdir","terraform-cli","user-error"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}