{"record":{"id":"e20e5fe2bce23832","repo":"hashicorp/nomad","slug":"cannot-create-configuration-directory-s","errorCode":null,"errorMessage":"cannot create configuration directory - %s","messagePattern":"cannot create configuration directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":266,"sourceCode":"\t// If the config or data directory are unset, default them\n\tif opts.configDir == \"\" {\n\t\topts.configDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, \"config\")\n\t}\n\tif opts.dataDir == \"\" {\n\t\topts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, \"data\")\n\t}\n\n\tvar err error\n\tif opts.configDir, err = c.winPaths.Expand(opts.configDir); err != nil {\n\t\treturn fmt.Errorf(\"cannot generate configuration path - %s\", err)\n\t}\n\tif opts.dataDir, err = c.winPaths.Expand(opts.dataDir); err != nil {\n\t\treturn fmt.Errorf(\"cannot generate data path - %s\", err)\n\t}\n\n\t// Ensure directories exist\n\tif err = c.winPaths.CreateDirectory(opts.configDir, true); err != nil {\n\t\treturn fmt.Errorf(\"cannot create configuration directory - %s\", err)\n\t}\n\n\tif err = c.winPaths.CreateDirectory(opts.dataDir, true); err != nil {\n\t\treturn fmt.Errorf(\"cannot create data directory - %s\", err)\n\t}\n\n\t// Check if any configuration files exist\n\tmatches, _ := filepath.Glob(filepath.Join(opts.configDir, \"*\"))\n\tif len(matches) < 1 {\n\t\tf, err := os.Create(filepath.Join(opts.configDir, \"config.hcl\"))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not create default configuration file - %s\", err)\n\t\t}\n\t\tfmt.Fprintf(f, strings.TrimSpace(`\n# Full configuration options can be found at https://developer.hashicorp.com/nomad/docs/configuration\n\ndata_dir  = \"%s\"\nbind_addr = \"0.0.0.0\"","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L248-L284","documentation":"After expanding paths, configInstall calls c.winPaths.CreateDirectory(opts.configDir, true) to ensure the configuration directory exists. This error wraps any failure from that creation — permission denied, invalid path, or an existing file conflicting with the directory name.","triggerScenarios":"Running 'nomad windows service install' when the expanded configDir cannot be created: no write permission at the parent (e.g. Program Files without elevation), a file already exists at the configDir path, or the path is on an unavailable drive.","commonSituations":"Installing without Administrator rights; config-dir pointing inside a read-only location; a previous botched install left a regular file named like the directory; network drive not reachable at install time.","solutions":["Run the install command from an elevated (Administrator) prompt","Choose a writable location such as C:\\ProgramData\\nomad as -config-dir","Check whether a file (not a directory) already exists at the target path and remove/rename it","Verify the drive/volume is present and writable"],"exampleFix":"// before (non-elevated shell)\nnomad windows service install -config-dir \"C:\\Windows\\System32\\nomad\"\n// after (elevated, writable location)\nnomad windows service install -config-dir \"C:\\ProgramData\\nomad\"","handlingStrategy":"validation","validationCode":"// Pre-check: parent of configDir writable and target not an existing file\nif fi, err := os.Stat(configDir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", configDir)\n}\nif err := os.MkdirAll(filepath.Dir(configDir), 0o755); err != nil {\n    return fmt.Errorf(\"parent not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run installs elevated so protected paths are writable","Pre-create the config directory with correct ACLs","Remove conflicting files that occupy the directory path","Avoid network drives for config storage"],"tags":["windows","directory","permissions"],"backgroundTag":"directory-creation-permission-denied","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}