hashicorp/terraform · error

architecture portion must not contain whitespace

Error message

architecture portion must not contain whitespace

What it means

Returned by ParsePlatform when the architecture portion (substring after the underscore) contains any of space, tab, newline, or carriage return. Mirrors the OS whitespace check; runs only after the two-part split succeeds.

Solutions

  1. Trim surrounding whitespace from the platform string before parsing.
  2. When reading platform from a file, strip the trailing newline (e.g. via strings.TrimSpace).
  3. Quote shell variables to avoid word-splitting.
  4. Validate user input rejects whitespace before passing to ParsePlatform.

Example fix

// before
line, _ := bufio.NewReader(f).ReadString('\n')
p, err := ParsePlatform(line) // line has trailing \n
// after
line, _ := bufio.NewReader(f).ReadString('\n')
p, err := ParsePlatform(strings.TrimSpace(line))
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: A platform string like 'linux_amd64 ' (trailing space), 'linux_amd64\t', or 'linux_am d64'. The whitespace lives in the arch token rather than the OS token.

Common situations: Trailing newline or space from reading a file line into ParsePlatform; shell word-splitting on the second token; config formatter inserting whitespace.

Related errors


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

Appendix: source

Thrown at internal/getproviders/types.go:126

	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,
}

// PackageMeta represents the metadata related to a particular downloadable

View on GitHub (pinned to d32a084675)