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
- Set HOME explicitly: 'export HOME=/root' (or the user's real home) before running Terraform.
- In Docker, run with a real user/home: '--user $(id -u):$(id -g)' plus '--env HOME=/tmp' or install the passwd entry.
- 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
- Set HOME explicitly in containers/CI runners.
- In distroless images, install a passwd entry or set TF_DATA_DIR / TF_CLI_CONFIG_FILE.
- Verify the runtime user has a resolvable home directory.
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
- building Storage Accounts client: %+v
- retrieving container client: %v
- no storage domain suffix defined for environment: %s
- Failed to get absolute path of the configuration directory:
- can't locate credentials file: %s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/c53925c0f9d70463.
Report an issue: GitHub.