hashicorp/packer · error

Error creating zip: %s

Error message

Error creating zip: %s

What it means

The zip archiving step inside Packer's compress post-processor failed. createZipArchive writes each artifact file into a zip stream layered on the compression writer; any open/stat/header/write error is wrapped as 'Error creating zip'. The build stops and the output archive is unusable.

Source

Thrown at post-processor/compress/post-processor.go:221

	compression := p.config.Algorithm
	if compression == "" {
		compression = "no compression"
	}

	// Build an archive, if we're supposed to do that.
	switch p.config.Archive {
	case "tar":
		ui.Say(fmt.Sprintf("Tarring %s with %s", target, compression))
		err = createTarArchive(artifact.Files(), output)
		if err != nil {
			return nil, false, false, fmt.Errorf("Error creating tar: %s", err)
		}
	case "zip":
		ui.Say(fmt.Sprintf("Zipping %s", target))
		err = createZipArchive(artifact.Files(), output)
		if err != nil {
			return nil, false, false, fmt.Errorf("Error creating zip: %s", err)
		}
	default:
		// Filename indicates no tarball (just compress) so we'll do an io.Copy
		// into our compressor.
		if len(artifact.Files()) != 1 {
			return nil, false, false, fmt.Errorf(
				"Can only have 1 input file when not using tar/zip. Found %d "+
					"files: %v", len(artifact.Files()), artifact.Files())
		}
		archiveFile := artifact.Files()[0]
		ui.Say(fmt.Sprintf("Archiving %s with %s", archiveFile, compression))

		source, err := os.Open(archiveFile)
		if err != nil {
			return nil, false, false, fmt.Errorf(
				"Failed to open source file %s for reading: %s",
				archiveFile, err)
		}

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Inspect the wrapped inner error for the exact failing file or write condition
  2. Ensure artifact files are readable by the Packer process
  3. Free disk space or move output to a larger volume
  4. Retry the build to rule out a transient I/O error
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify artifact files are readable and disk has headroom
for _, f := range artifact.Files() {
    if _, err := os.Open(f); err != nil { return err }
}
// approximate required space = sum of input sizes
var need int64
for _, f := range artifact.Files() { if fi, _ := os.Stat(f); fi != nil { need += fi.Size() } }

Try / catch

// Go: branch on the wrapped error text
if err != nil {
    if strings.Contains(err.Error(), "Error creating zip") {
        // inspect inner cause (ENOSPC, permission) and remediate
    }
    return err
}

Prevention

When it happens

Trigger: PostProcess with archive set to "zip" and createZipArchive returning an error: artifact file unreadable, zip header creation fails, or a write to the zip writer errors (disk full, broken output file).

Common situations: Disk exhaustion while zipping large images; artifact files with permissions the Packer process cannot read; output path on a filesystem that hit a quota or I/O error mid-write.

Related errors


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