hashicorp/terraform · error

invalid registry namespace

Error message

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

What it means

Thrown when the namespace segment (parts[0]) is neither '*' nor accepted by tfaddr.ParseProviderNamespace, which enforces registry namespace naming rules (lowercase, limited character set, length bounds). NOTE: the error message at multi_source.go:178 interpolates parts[1] (the type) into a message about the namespace — the printed %q is the wrong segment; the actual failing value is parts[0] (the namespace).

Solutions

  1. Fix the NAMESPACE segment (parts[0], the segment before the type) to a lowercase registry-legal namespace — be aware the error text misleadingly shows the type.
  2. If you want any namespace, use '*' as the namespace segment.
  3. Re-read the pattern as host?/namespace/type and edit the first non-host segment, not the last.
  4. File/track the message bug separately so future readers are not misled.

Example fix

// before (error text points at 'aws', but the bad segment is the namespace)
include = ["HashiCorp/aws"]

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

Strategy: validation

Validate before calling

import tfaddr "github.com/hashicorp/terraform-registry-address"

func validNamespaceSegment(ns string) error {
    if ns == "*" {
        return nil
    }
    return tfaddr.ParseProviderNamespace(ns)
}

// NOTE: the library's error message for error 903 prints parts[1] (the TYPE),
// not the namespace. Validate the namespace (the first non-host segment)
// yourself and do not trust the printed %q when diagnosing.

Prevention

When it happens

Trigger: Patterns like 'HashiCorp/aws' (uppercase namespace), 'my_namespace/aws' (underscore), 'hashi.corp/aws' (dot in namespace), or an empty namespace '*/aws' style misuse. Triggered at multi_source.go:176-178 via normalizeProviderNamespaceOrWildcard -> tfaddr.ParseProviderNamespace.

Common situations: Using a namespace with mixed case or punctuation (private registry namespaces sometimes differ from display names); relying on the misleading error text (which shows the type, not the namespace) and 'fixing' the wrong segment; namespaces copied from a URL that include a trailing path.

Related errors


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

Appendix: 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 d32a084675)