hashicorp/terraform · error

invalid registry namespace %q in provider matching pattern %

Error message

invalid registry namespace %q in provider matching pattern %q: must either be the wildcard * or a literal namespace

What it means

The namespace (middle segment) is normalized via normalizeProviderNamespaceOrWildcard: it must be exactly "*" or pass tfaddr.ParseProviderNamespace. Any other value yields this error, quoting the offending namespace and the full pattern. (Note the code reports parts[1] as the namespace value, which is the type segment, but the failure is triggered by the namespace normalization.)

Source

Thrown at internal/getproviders/multi_source.go:178

				normalHost, err := svchost.ForComparison(givenHost)
				if err != nil {
					return nil, fmt.Errorf("invalid hostname in provider matching pattern %q: %s", str, err)
				}

				// The remaining code below deals only with the namespace/type portions.
				host = normalHost
			}

			parts = parts[1:]
		}

		pType, err := normalizeProviderNameOrWildcard(parts[1])
		if err != nil {
			return nil, fmt.Errorf("invalid provider type %q in provider matching pattern %q: must either be the wildcard * or a provider type name", parts[1], str)
		}
		namespace, err := normalizeProviderNamespaceOrWildcard(parts[0])
		if err != nil {
			return nil, fmt.Errorf("invalid registry namespace %q in provider matching pattern %q: must either be the wildcard * or a literal namespace", parts[1], str)
		}

		ret[i] = addrs.Provider{
			Hostname:  host,
			Namespace: namespace,
			Type:      pType,
		}

		if ret[i].Hostname == svchost.Hostname(Wildcard) && !(ret[i].Namespace == Wildcard && ret[i].Type == Wildcard) {
			return nil, fmt.Errorf("invalid provider matching pattern %q: hostname can be a wildcard only if both namespace and provider type are also wildcards", str)
		}
		if ret[i].Namespace == Wildcard && ret[i].Type != Wildcard {
			return nil, fmt.Errorf("invalid provider matching pattern %q: namespace can be a wildcard only if the provider type is also a wildcard", str)
		}
	}
	return ret, nil
}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Lowercase the namespace and use only allowed characters.
  2. Fix double-slashes that produce an empty namespace segment.
  3. Use "*" to wildcard the namespace (type must then also be "*").

Example fix

# before
include = ["HashiCorp/aws"]

# after
include = ["hashicorp/aws"]
Defensive patterns

Strategy: validation

Validate before calling

// Validate the namespace segment before parsing.
if ns := parts[len(parts)-2]; ns != "*" {
    if err := validateNamespace(ns); err != nil {
        return fmt.Errorf("namespace %q invalid: %w", ns, err)
    }
}

Prevention

When it happens

Trigger: Pattern's namespace segment is invalid: uppercase, empty (double slash), or contains characters ParseProviderNamespace rejects. e.g. "HashiCorp/aws" or "hashicorp//aws".

Common situations: Mixed-case namespace from a provider's display name; empty namespace from a typoed double slash; disallowed punctuation in the namespace.

Related errors


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