hashicorp/terraform · error

GitHub URLs should be github.com/username/repo

Error message

GitHub URLs should be github.com/username/repo

What it means

Thrown by detectGitHub when a source starting with 'github.com/' splits into fewer than 3 parts. The detector requires at minimum host/username/repo (parts[0..2]); anything shorter has no repo component and cannot form a valid git HTTP address.

Solutions

  1. Provide the full repository path: 'github.com/USERNAME/REPO'.
  2. Copy the URL directly from the GitHub repo page (including the repo name).
  3. Optionally append ref via query string: 'github.com/USERNAME/REPO?ref=v1.2.3'.

Example fix

# before (no repo)
source = "github.com/hashicorp"

# after
source = "github.com/hashicorp/example"
Defensive patterns

Strategy: validation

Validate before calling

// Validate a GitHub shorthand has at least host/user/repo.
// func validGitHubShorthand(src string) error {
//     if !strings.HasPrefix(src, "github.com/") { return nil }
//     if len(strings.Split(src, "/")) < 3 {
//         return fmt.Errorf("GitHub source must be github.com/USER/REPO")
//     }
//     return nil
// }

Prevention

When it happens

Trigger: Source is 'github.com/' alone or 'github.com/<username>' with no repo segment; the prefix matches but the path is incomplete.

Common situations: User copies only the org/profile URL instead of a repository URL; trailing slash artifacts; autocomplete/copy mistake.

Related errors


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

Appendix: source

Thrown at internal/getmodules/moduleaddrs/detect_git.go:47

		return "", false, nil
	}

	return "git::" + u.String(), true, nil
}

// detectGitHub detects shorthand schemeless references to github.com and
// translates them into git HTTP source addresses.
func detectGitHub(src string) (string, bool, error) {
	if len(src) == 0 {
		return "", false, nil
	}

	if strings.HasPrefix(src, "github.com/") {
		src, rawQuery, _ := strings.Cut(src, "?")

		parts := strings.Split(src, "/")
		if len(parts) < 3 {
			return "", false, fmt.Errorf(
				"GitHub URLs should be github.com/username/repo")
		}

		urlStr := fmt.Sprintf("https://%s", strings.Join(parts[:3], "/"))
		url, err := url.Parse(urlStr)
		if err != nil {
			return "", true, fmt.Errorf("error parsing GitHub URL: %s", err)
		}
		url.RawQuery = rawQuery

		if !strings.HasSuffix(url.Path, ".git") {
			url.Path += ".git"
		}

		if len(parts) > 3 {
			url.Path += "//" + strings.Join(parts[3:], "/")
		}

View on GitHub (pinned to d32a084675)