hashicorp/terraform · error

blank output

Error message

blank output

What it means

Returned at config_unix.go:52 when Terraform's home-directory resolution falls back to os/user.Current() on Unix systems and the returned user struct has an empty HomeDir field. This indicates a broken or misconfigured user database (e.g., /etc/passwd missing the home directory entry). The error 'blank output' means the OS reported a user but with no home directory path.

Solutions

  1. Set the HOME environment variable explicitly: 'export HOME=/root' or the appropriate path.
  2. Fix the /etc/passwd entry for the current user to include a valid home directory.
  3. In Docker, ensure the user has a proper home directory: 'USER root' or add 'usermod -d /home/user user'.
  4. Set TF_DATA_DIR to a known path to reduce dependency on home directory resolution.

Example fix

# before: HOME unset, /etc/passwd broken
terraform init
// error: blank output

# after: set HOME explicitly
export HOME=/root
terraform init
Defensive patterns

Strategy: validation

Validate before calling

// Validate HOME is set before running terraform:
// if os.Getenv("HOME") == "" {
//     os.Setenv("HOME", "/root") // or appropriate path
// }
// exec.Command("terraform", "init")

Prevention

When it happens

Trigger: On Unix/Linux, the HOME environment variable is not set (the earlier env-var check failed), so the code falls back to user.Current(). The OS returns a user record, but HomeDir is empty — typically due to a malformed /etc/passwd entry or running in a minimal container/sandbox without proper user setup.

Common situations: Running terraform in minimal Docker containers with broken user setup; chroot or sandboxed environments without /etc/passwd; system accounts with no home directory; misconfigured LDAP/NIS user databases.

Related errors


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

Appendix: source

Thrown at internal/command/cliconfig/config_unix.go:52

func homeDir() (string, error) {
	// First prefer the HOME environmental variable
	if home := os.Getenv("HOME"); home != "" {
		// FIXME: homeDir gets called from globalPluginDirs during init, before
		// the logging is set up.  We should move meta initializtion outside of
		// init, but in the meantime we just need to silence this output.
		//log.Printf("[DEBUG] Detected home directory from env var: %s", home)

		return home, nil
	}

	// If that fails, try build-in module
	user, err := user.Current()
	if err != nil {
		return "", err
	}

	if user.HomeDir == "" {
		return "", errors.New("blank output")
	}

	return user.HomeDir, nil
}

View on GitHub (pinned to d32a084675)