hashicorp/terraform · error

architecture portion must not contain whitespace

Error message

architecture portion must not contain whitespace

What it means

Returned by ParsePlatform (internal/getproviders/types.go:126) when the architecture segment (the part after the underscore) contains space/tab/newline/CR, detected via strings.ContainsAny(arch, " \t\n\r"). Symmetric to the OS check; it ensures the ARCH component is a clean token before building a Platform value used in mirror paths and registry queries.

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

Solutions

  1. Source the arch portion from runtime.GOARCH or a fixed allow-list (amd64, arm64, arm, 386, darwin variants).
  2. Trim whitespace from the arch segment before calling ParsePlatform.
  3. Validate the segment against ^\S+$ and a known arch set before parsing.
  4. Fix upstream concatenation that introduces spaces (use strings.Join with empty separator).

Example fix

// before
arch := strings.Join([]string{"amd", "64"}, " ")  // "amd 64"
p, err := ParsePlatform("linux_" + arch)  // -> architecture portion must not contain whitespace

// after
arch := strings.Join([]string{"amd", "64"}, "")  // "amd64"
p, err := ParsePlatform("linux_" + arch)
Defensive patterns

Strategy: validation

Validate before calling

func archSegmentClean(s string) bool {
    parts := strings.SplitN(s, "_", 2)
    if len(parts) != 2 { return false }
    return !strings.ContainsAny(parts[1], " \t\n\r")
}

Type guard

var knownArch = map[string]bool{"amd64":true,"arm64":true,"arm":true,"386":true}
func archIsKnown(s string) bool {
    parts := strings.SplitN(s, "_", 2)
    return len(parts) == 2 && knownArch[parts[1]]
}

Try / catch

p, err := getproviders.ParsePlatform(raw)
if err != nil && strings.Contains(err.Error(), "architecture portion") {
    raw = strings.TrimSpace(strings.TrimRight(raw, " \t\n\r"))
    p, err = getproviders.ParsePlatform(raw)
}

Prevention

When it happens

Trigger: Calling ParsePlatform on a string like "linux_am d64", "linux_amd64\n", or a value where the arch portion was concatenated from a list/slice that introduced whitespace.

Common situations: Joining a slice to form the arch with strings.Join(" ") instead of "", arch values read from files with trailing newlines, user-typed platform specifiers with spaces, or templating bugs that append a trailing separator.

Related errors


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