hashicorp/terraform · error
There is no configuration directory at %s
Error message
There is no configuration directory at %s
What it means
Emitted by terraform fmt's processDir when os.ReadDir reports the target path does not exist (os.IsNotExist). It is a user-facing simplification because the raw ReadDir error is not end-user appropriate. The %s is the normalized path argument passed to `terraform fmt`. The command continues processing other paths but records this diagnostic.
Source
Thrown at internal/command/fmt.go:239
_, err = w.Write(result)
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to write result"))
}
}
return diags
}
func (c *FmtCommand) processDir(path string, stdout io.Writer) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
log.Printf("[TRACE] terraform fmt: looking for files in %s", path)
entries, err := os.ReadDir(path)
if err != nil {
switch {
case os.IsNotExist(err):
diags = diags.Append(fmt.Errorf("There is no configuration directory at %s", path))
default:
// ReadDir does not produce error messages that are end-user-appropriate,
// so we'll need to simplify here.
diags = diags.Append(fmt.Errorf("Cannot read directory %s", path))
}
return diags
}
for _, info := range entries {
name := info.Name()
if configs.IsIgnoredFile(name) {
continue
}
subPath := filepath.Join(path, name)
if info.IsDir() {
if c.recursive {
subDiags := c.processDir(subPath, stdout)
diags = diags.Append(subDiags)View on GitHub (pinned to c9def3e214)
Solutions
- Verify the path exists and is spelled correctly: `ls <dir>` before running fmt.
- Omit the argument to operate on the current directory (`terraform fmt`) which always exists.
- In scripts, guard with a check: `[ -d "$DIR" ] && terraform fmt "$DIR"`.
- Fix the working directory / variable expansion that produced the bogus path.
Example fix
# before $ terraform fmt ./moodules # after $ terraform fmt ./modules
Defensive patterns
Strategy: validation
Validate before calling
// Verify the directory exists before calling terraform fmt on it.
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
return fmt.Errorf("refusing to fmt: %q is not an existing directory", dir)
} Prevention
- Always resolve fmt path arguments against a known working directory.
- In scripts, guard with `[ -d "$DIR" ]` before invoking terraform fmt.
- Default to running `terraform fmt` with no argument (current dir) to avoid path typos.
When it happens
Trigger: Invoking `terraform fmt <dir>` or `terraform fmt -recursive <dir>` where <dir> does not exist on disk. Also when a relative path resolves against an unexpected working directory (e.g. running fmt from the wrong cwd, a typo in the path, or a path to a directory that was deleted).
Common situations: Typos in the directory argument; running `terraform fmt ./moodules` instead of `./modules`. CI jobs that cd into a non-existent directory before invoking fmt. Scripts that build the path from an unset variable, yielding an empty/missing segment. Renaming a module directory without updating the fmt script.
Related errors
- Failed to open script '%s': %v
- Failed to get absolute path of the configuration directory:
- No file or directory at %s
- Cannot read directory %s
- Error loading statefile: %w
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/757e8d7d5a1d51a4.
Report an issue: GitHub.