hashicorp/packer · error

Invalid plugin type %q in source: %s"

Error message

Invalid plugin type %q in source: %s"

What it means

ParsePluginSourceString validates the plugin type (the final path segment of the source) with ParsePluginPart. If it fails, this error reports the invalid type and the underlying reason, with an awkward trailing quote in the message text itself.

Source

Thrown at hcl2template/addrs/plugin.go:159

	if url != nil && url.Fragment != "" {
		errs = append(errs, "A source URL must not contain a fragment (e.g. #anchor).")
	}

	if errs != nil {
		errsMsg := &strings.Builder{}
		for _, err := range errs {
			fmt.Fprintf(errsMsg, "* %s\n", err)
		}

		return nil, fmt.Errorf("The provided source URL is invalid.\nThe following errors have been discovered:\n%s\nA valid source looks like \"github.com/hashicorp/happycloud\"", errsMsg)
	}

	// check the 'name' portion, which is always the last part
	_, givenName := path.Split(str)
	_, err = ParsePluginPart(givenName)
	if err != nil {
		return nil, fmt.Errorf(`Invalid plugin type %q in source: %s"`, givenName, err)
	}

	// Due to how plugin executables are named and plugin git repositories
	// are conventionally named, it's a reasonable and
	// apparently-somewhat-common user error to incorrectly use the
	// "packer-plugin-" prefix in a plugin source address. There is
	// no good reason for a plugin to have the prefix "packer-" anyway,
	// so we've made that invalid from the start both so we can give feedback
	// to plugin developers about the packer- prefix being redundant
	// and give specialized feedback to folks who incorrectly use the full
	// packer-plugin- prefix to help them self-correct.
	const redundantPrefix = "packer-"
	const userErrorPrefix = "packer-plugin-"
	if strings.HasPrefix(givenName, redundantPrefix) {
		if strings.HasPrefix(givenName, userErrorPrefix) {
			// Likely user error. We only return this specialized error if
			// whatever is after the prefix would otherwise be a
			// syntactically-valid plugin type, so we don't end up advising

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Fix the last path segment to contain only letters, digits, and single dashes
  2. Remove any 'packer-plugin-' prefix from the type segment
  3. Re-check the wrapped error text for the exact character problem

Example fix

// before
source = "github.com/org/packer_plugin_my_data"  // invalid: underscores
// after
source = "github.com/org/my-data"
Defensive patterns

Strategy: validation

Validate before calling

name := src[strings.LastIndex(src, "/")+1:]
if !regexp.MustCompile(`^[a-zA-Z0-9](-?[a-zA-Z0-9])*$`).MatchString(name) { /* fix type before packer init */ }

Prevention

When it happens

Trigger: Calling ParsePluginSourceString with a source whose last segment contains invalid characters, consecutive dashes, or leading/trailing dashes, e.g. 'github.com/hashicorp/amazon_' or 'github.com/org/--type'.

Common situations: Using underscore-separated repo names ('packer_plugin_x'); accidentally leaving the 'packer-plugin-' prefix in the type; copy-paste artifacts in the last segment.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/89a9405e676ef417. Report an issue: GitHub.