hashicorp/terraform · error

OS portion must not contain whitespace

Error message

OS portion must not contain whitespace

What it means

Returned by ParsePlatform when the OS portion (the substring before the underscore) contains any of space, tab, newline, or carriage return. Emitted only after the two-part split succeeds; it guards against whitespace that the underscore split would not catch.

Solutions

  1. Trim surrounding whitespace from the platform string before parsing.
  2. Quote CLI args and config values to prevent shell word-splitting.
  3. Audit the source of the platform string for stray spaces or tabs.
  4. If the value is user-supplied, validate with strings.TrimSpace before ParsePlatform.

Example fix

// before
p, err := ParsePlatform(" linux_amd64")
// after
p, err := ParsePlatform(strings.TrimSpace(" linux_amd64"))
Defensive patterns

Strategy: validation

Validate before calling

// Reject OS tokens with whitespace before parsing.
func validatePlatformTokens(s string) error {
    parts := strings.Split(s, "_")
    if len(parts) != 2 { return errors.New("bad shape") }
    if strings.ContainsAny(parts[0], " \t\n\r") { return errors.New("OS has whitespace") }
    return nil
}

Prevention

When it happens

Trigger: A platform string like 'linu x_amd64', '\tlinux_amd64', 'linux\n_amd64' where the OS token has embedded whitespace. Usually a copy-paste or shell-quoting artifact.

Common situations: Trailing space introduced by shell expansion; tab from a malformed config file; copy-paste from a table introducing a non-breaking space (note: NBSP is U+00A0, technically not in the ContainsAny set, but a regular space often is).

Related errors


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

Appendix: source

Thrown at internal/getproviders/types.go:123

	switch {
	case p.OS != other.OS:
		return p.OS < other.OS
	default:
		return p.Arch < other.Arch
	}
}

// ParsePlatform parses a string representation of a platform, like
// "linux_amd64", or returns an error if the string is not valid.
func ParsePlatform(str string) (Platform, error) {
	parts := strings.Split(str, "_")
	if len(parts) != 2 {
		return Platform{}, fmt.Errorf("must be two words separated by an underscore")
	}

	os, arch := parts[0], parts[1]
	if strings.ContainsAny(os, " \t\n\r") {
		return Platform{}, fmt.Errorf("OS portion must not contain whitespace")
	}
	if strings.ContainsAny(arch, " \t\n\r") {
		return Platform{}, fmt.Errorf("architecture portion must not contain whitespace")
	}

	return Platform{
		OS:   os,
		Arch: arch,
	}, nil
}

// CurrentPlatform is the platform where the current program is running.
//
// If attempting to install providers for use on the same system where the
// installation process is running, this is the right platform to use.
var CurrentPlatform = Platform{
	OS:   runtime.GOOS,
	Arch: runtime.GOARCH,

View on GitHub (pinned to d32a084675)