hashicorp/terraform · error
Error validating destination directory: %s
Error message
Error validating destination directory: %s
What it means
Emitted by InitCommand.run in the -from-module branch when configs.IsEmptyDir(path, testsDir) returns an error (init_run.go:67-69). IsEmptyDir walks the target directory to confirm it is empty before copying the module source into it; any failure to stat/read that directory produces this message with the underlying error.
Source
Thrown at internal/command/init_run.go:69
// Get the working directory
path := c.Meta.WorkingDir.RootModuleDir()
if err := c.storePluginPath(c.pluginPath); err != nil {
diags = diags.Append(fmt.Errorf("Error saving -plugin-dir to workspace directory: %s", err))
view.Diagnostics(diags)
return 1
}
// Initialization can be aborted by interruption signals
ctx, done := c.InterruptibleContext(c.CommandContext())
defer done()
if initArgs.FromModule != "" {
src := initArgs.FromModule
empty, err := configs.IsEmptyDir(path, initArgs.TestsDirectory)
if err != nil {
diags = diags.Append(fmt.Errorf("Error validating destination directory: %s", err))
view.Diagnostics(diags)
return 1
}
if !empty {
diags = diags.Append(errors.New(strings.TrimSpace(errInitCopyNotEmpty)))
view.Diagnostics(diags)
return 1
}
view.Output(views.CopyingConfigurationMessage, src)
hooks := uiModuleInstallHooks{
Ui: c.Ui,
ShowLocalPaths: false, // since they are in a weird location for init
View: view,
}
ctx, span := tracer.Start(ctx, "-from-module=...", trace.WithAttributes(View on GitHub (pinned to c9def3e214)
Solutions
- Check permissions/ownership of the target directory: `ls -la <dir>` and fix with chmod/chown.
- Remove broken symlinks inside the target: `find <dir> -xtype l -delete`.
- If the directory is not needed, delete it and let init recreate it: `rm -rf <dir> && terraform init -from-module=...`.
- Verify the underlying filesystem/mount is healthy and readable.
Example fix
# before $ terraform init -from-module=git::ssh://... # target dir unreadable # after $ chmod a+rx ./target && terraform init -from-module=git::ssh://... ./target
Defensive patterns
Strategy: validation
Validate before calling
// Before -from-module, confirm the destination is an empty, readable dir.
if entries, err := os.ReadDir(dest); err != nil {
return fmt.Errorf("destination %q unreadable: %w", dest, err)
} else if len(entries) != 0 {
return fmt.Errorf("destination %q is not empty", dest)
} Prevention
- Point -from-module at a fresh, empty, writable directory.
- Ensure the destination directory has read+execute+write for the terraform user.
- Clean broken symlinks and stale .terraform before re-using a directory.
When it happens
Trigger: Running `terraform init -from-module=<source>` into a target directory that exists but cannot be read or stat'd: permission denied on the directory or one of its entries, an I/O error from the filesystem, or a symlink loop inside the target dir.
Common situations: Re-initializing into a directory with restrictive permissions; target dir created by a different user/UID; failing disk; container bind-mount with incorrect ownership; leftover broken symlinks from a prior tool run.
Related errors
- Error saving -plugin-dir to workspace directory: %s
- Error checking configuration: %s
- error deleting workspace %s: %w
- cannot create temporary file to update credentials: %s
- could not write lock info for %q: %s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/f575a9212ca50aa1.
Report an issue: GitHub.