hashicorp/packer · error

failed to download Packer release zip: %w

Error message

failed to download Packer release zip: %w

What it means

Wrapped when downloadURLToTempFile fails to download the Packer release zip (e.g. packer_<v>_<goos>_<goarch>.zip) into a temp file. Covers temp-file creation errors, HTTP request errors, non-200 status, and write/close failures. The partial temp file is removed automatically; the retry.Config wrapper retries up to 3 times.

Source

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

	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)
			}
		}()

		sumsContent, err := downloadChecksumFile(ctx, client, shaSumsURL)
		if err != nil {
			return fmt.Errorf("failed to download release checksums: %w", err)
		}

		expectedSHA, err := expectedZipSHA256FromSums(sumsContent, fileName)
		if err != nil {
			return fmt.Errorf("failed to resolve expected checksum: %w", err)
		}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Check the exact zip URL in the error/logs exists (curl -I); a 404 usually means a transient index/artifact mismatch — retry the build.
  2. Free disk space or fix TMPDIR permissions on the build host.
  3. Verify network/proxy access to releases.hashicorp.com.
  4. Confirm the target platform has an official Packer build for that GOOS/GOARCH.

Example fix

// caller-side pre-check before invoking the auto-download flow
if out, err := exec.Command("df", "-h", os.TempDir()).Output(); err == nil {
	log.Println("tmp space:\n", string(out)) // ensure room for the ~150MB zip
}
Defensive patterns

Strategy: retry

Validate before calling

url := fmt.Sprintf("https://releases.hashicorp.com/packer/%s/packer_%s_%s_%s.zip", v, v, goos, goarch)
resp, err := http.Head(url)
if err != nil || resp.StatusCode != http.StatusOK {
	return fmt.Errorf("zip artifact not available: HTTP status issue for %s", url)
}
resp.Body.Close()

Try / catch

if err := provisioner.Provision(...); err != nil {
	if strings.Contains(err.Error(), "failed to download Packer release zip") {
		// check disk space (TMPDIR) and network, then retry once
	}
}

Prevention

When it happens

Trigger: downloadURLToTempFile(ctx, client, zipURL, ".zip") errors: os.CreateTemp fails, http request fails, HTTP status != 200 for the zip URL, io.Copy write error, or f.Close error.

Common situations: Wrong GOOS/GOARCH combination producing a nonexistent artifact URL (HTTP 404); disk full or read-only /tmp so os.CreateTemp fails; interrupted download mid-transfer; proxy blocking the artifact URL; newly released version whose zip is not yet propagated on the CDN.

Related errors


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