hashicorp/terraform · error

Error validating destination directory

Error message

Error validating destination directory: %s

What it means

Thrown when -from-module is set and configs.IsEmptyDir(path, TestsDirectory) returns an error while validating the destination directory before copying the source module. The %s is the underlying error from IsEmptyDir.

Solutions

  1. Check read permissions on the destination directory: `ls -la <path>`.
  2. Ensure the destination exists and is a valid, traversable directory.
  3. Retry from a clean, writable empty directory.

Example fix

$ mkdir -p ./mod && chmod u+rx ./mod && terraform init -from-module=github.com/x/y ./mod
Defensive patterns

Strategy: validation

Validate before calling

// Verify destination dir is readable and empty before -from-module.
func readableAndEmpty(p string) error {
    e, err := configs.IsEmptyDir(p, "")
    if err != nil { return err }
    if !e { return errors.New("not empty") }
    return nil
}

Prevention

When it happens

Trigger: Running `terraform init -from-module=...` when the destination directory cannot be inspected (permission denied, I/O error, broken symlink) or when IsEmptyDir encounters a read failure on a subdir.

Common situations: Destination directory not readable; path collision; running from a directory with permission issues; filesystem errors during traversal.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/f575a9212ca50aa1. Report an issue: GitHub.

Appendix: 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.LogConfigurationCopyingStart(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 d32a084675)