hashicorp/packer · error

failed to determine latest Packer version: %w

Error message

failed to determine latest Packer version: %w

What it means

Wrapped by downloadPackerRelease when fetchLatestPackerVersion cannot resolve the latest stable Packer version from the releases index (releases.hashicorp.com/packer/index.json). Failures include request construction errors, network errors, non-200 HTTP status, JSON decode failures, or an index with no parseable stable (non-prerelease) versions. It is retried up to 3 times (5s delay) inside retry.Config before surfacing, then wrapped again by error 457.

Source

Thrown at provisioner/hcp-sbom/packer_release_fetch.go:229

}

// downloadPackerRelease fetches the latest stable Packer version from the
// HashiCorp releases index (releases.hashicorp.com/packer/index.json), then
// downloads and checksum-verifies the zip for the given GOOS/GOARCH.
// All HTTP operations are retried up to three times.
func downloadPackerRelease(ctx context.Context, goos, goarch string) (string, error) {
	base := getReleaseBaseURL()
	client := &http.Client{Timeout: 5 * time.Minute}

	var zipPath string
	err := retry.Config{
		Tries:      3,
		RetryDelay: func() time.Duration { return 5 * time.Second },
	}.Run(ctx, func(ctx context.Context) error {
		// Resolve the latest stable version from the releases index.
		v, err := fetchLatestPackerVersion(ctx, client)
		if err != nil {
			return fmt.Errorf("failed to determine latest Packer version: %w", err)
		}

		fileName := fmt.Sprintf("packer_%s_%s_%s.zip", v, goos, goarch)
		zipURL := fmt.Sprintf("%s/packer/%s/%s", base, v, fileName)
		shaSumsURL := fmt.Sprintf("%s/packer/%s/packer_%s_SHA256SUMS", base, v, v)

		log.Printf("[INFO] Downloading and verifying Packer %s for %s/%s...", v, goos, goarch)

		candidateZipPath, err := downloadURLToTempFile(ctx, client, zipURL, ".zip")
		if err != nil {
			return fmt.Errorf("failed to download Packer release zip: %w", err)
		}
		keepCandidate := false
		defer func() {
			if !keepCandidate {
				_ = os.Remove(candidateZipPath)
			}
		}()

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Verify network connectivity from the build machine to https://releases.hashicorp.com/packer/index.json (curl it manually).
  2. Configure proxy environment variables (HTTP_PROXY/HTTPS_PROXY) if the build host is behind a proxy.
  3. Re-run the build: the fetch is retried 3 times with 5s delay, so transient outages may self-heal.
  4. If the endpoint is intentionally unreachable, pre-provision Packer on the guest instead of using the auto-download path.

Example fix

// before
v, err := fetchLatestPackerVersion(ctx, client)
if err != nil {
	return fmt.Errorf("failed to determine latest Packer version: %w", err)
}
// after (caller-side hardening: check reachability up front)
resp, err := http.Head("https://releases.hashicorp.com/packer/index.json")
if err != nil || resp.StatusCode != 200 {
	return errors.New("releases.hashicorp.com unreachable; fix network/proxy before running hcp-sbom auto_generate")
}
Defensive patterns

Strategy: retry

Validate before calling

resp, err := http.Get("https://releases.hashicorp.com/packer/index.json")
if err != nil {
	return fmt.Errorf("release index unreachable: %w", err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
	return fmt.Errorf("release index returned HTTP %d", resp.StatusCode)
}

Try / catch

if err := runBuild(); err != nil {
	var netErr net.Error
	if errors.As(err, &netErr) || strings.Contains(err.Error(), "failed to determine latest Packer version") {
		// back off and retry the whole build after network is verified
	}
}

Prevention

When it happens

Trigger: fetchLatestPackerVersion returns an error: http.NewRequestWithContext fails, client.Do fails (DNS/network/timeout), releases.hashicorp.com returns HTTP != 200 for /packer/index.json, the response body is not valid JSON matching releaseIndex, or no stable semver entries exist in the index.

Common situations: No internet access or DNS failure from the build machine; corporate proxy/firewall blocking releases.hashicorp.com; transient 5xx or CDN outage; TLS interception breaking the connection; a malformed or changed index.json schema.

Related errors


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