hashicorp/terraform · error

blank output

Error message

blank output

What it means

Returned by homeDir() in config_unix.go:52 when neither the HOME environment variable nor the OS user database provides a home directory (user.Current().HomeDir == ""). Terraform needs the home directory to locate ~/.terraformrc and ~/.terraform.d; without it, CLI config and plugin dirs cannot be resolved. This is a build of cliconfig, unix-only (the windows variant resolves differently).

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 c9def3e214)

Solutions

  1. Set HOME explicitly: 'export HOME=/root' (or the user's real home) before running Terraform.
  2. In Docker, run with a real user/home: '--user $(id -u):$(id -g)' plus '--env HOME=/tmp' or install the passwd entry.
  3. Use 'TF_CLI_CONFIG_FILE' / 'TF_DATA_DIR' env vars to point Terraform at explicit config and data dirs, bypassing home-dir lookup.

Example fix

# before: container with no HOME and no passwd entry
$ terraform init  # -> blank output
# after
$ export HOME=/app
$ terraform init
Defensive patterns

Strategy: validation

Validate before calling

// Ensure HOME is set before running Terraform (unix).
func ensureHome() error {
    if os.Getenv("HOME") == "" {
        home, err := os.UserHomeDir()
        if err != nil || home == "" {
            return errors.New("HOME is unset and no home directory could be determined; set HOME or TF_DATA_DIR")
        }
        os.Setenv("HOME", home)
    }
    return nil
}

Prevention

When it happens

Trigger: Line 34-53: os.Getenv("HOME") is empty AND user.Current() succeeds but its HomeDir field is empty -> errors.New("blank output"). Common in minimal containers/scratch images without a passwd entry or HOME set.

Common situations: Running Terraform in a Docker container (e.g. scratch/distroless) as a UID with no /etc/passwd entry and HOME unset; CI runners that strip environment variables; a misconfigured systemd unit missing 'Environment=HOME=...'.

Related errors


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