hashicorp/terraform · error

GitHub URLs should be github.com/username/repo

Error message

GitHub URLs should be github.com/username/repo

What it means

Returned by detectGitHub (detect_git.go:47) when a source string starts with 'github.com/' but has fewer than 3 path segments after splitting on '/'. The shorthand expects github.com/<username>/<repo> at minimum, so anything shorter (e.g. just 'github.com/' or 'github.com/username') is rejected as structurally incomplete.

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

Solutions

  1. Provide the full shorthand: github.com/<username>/<repo>, e.g. github.com/hashicorp/example.
  2. Optionally append a subdirectory path or query (e.g. ?ref=v1.2.0) after the repo.
  3. If you need a specific commit/branch, add ?ref=<git-ref>.
  4. Verify the URL with a browser before pasting it into source.

Example fix

# before
source = "github.com/hashicorp"

# after — include username AND repo
source = "github.com/hashicorp/example"
# optionally:
# source = "github.com/hashicorp/example//modules/vpc?ref=v1.0.0"
Defensive patterns

Strategy: validation

Validate before calling

// Validate a github.com shorthand has at least user/repo
func validGitHubShorthand(src string) bool {
    if !strings.HasPrefix(src, "github.com/") {
        return true
    }
    base := strings.SplitN(src, "?", 2)[0]
    return len(strings.Split(base, "/")) >= 3
}

Type guard

func isCompleteGitHubShorthand(src string) bool {
    if !strings.HasPrefix(src, "github.com/") {
        return false
    }
    base := strings.SplitN(src, "?", 2)[0]
    return len(strings.Split(base, "/")) >= 3
}

Prevention

When it happens

Trigger: A module source using the github.com shorthand but missing the repository segment. detectGitHub splits on '/', requires len(parts) >= 3, and otherwise returns this error. The source has already been confirmed to start with 'github.com/'.

Common situations: Writing source = "github.com/hashicorp" (missing repo) or source = "github.com/" (missing both). Truncated copy-paste of a GitHub URL. Forgetting the repo name when migrating from a local path.

Related errors


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