hashicorp/packer · error

Error creating tar: %s

Error message

Error creating tar: %s

What it means

The tar archiving step inside Packer's compress post-processor failed. createTarArchive writes every artifact file into a tar stream on top of the compression writer; any per-file or stream error is wrapped as 'Error creating tar'. This aborts the build and invalidates the partially written output file.

Source

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

				fmt.Errorf(errTmpl, p.config.Algorithm, err)
		}
		defer output.Close()
	default:
		output = outputFile
	}

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

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Read the wrapped inner error to identify the failing file or stream condition
  2. Verify all artifact files exist and are readable before the compress step
  3. Check free disk space in the output_directory / output path
  4. Re-run after cleaning stale output files that may conflict
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: ensure all artifact files exist and are readable
for _, f := range artifact.Files() {
    fi, err := os.Stat(f)
    if err != nil { return fmt.Errorf("artifact file missing: %s: %w", f, err) }
    if !fi.Mode().IsRegular() { return fmt.Errorf("not a regular file: %s", f) }
}

Try / catch

// Go: inspect the returned wrapped error
artifact, _, _, err := pp.PostProcess(ctx, ui, artifact)
if err != nil {
    if strings.Contains(err.Error(), "Error creating tar") {
        // log inner cause, free disk space, retry
    }
    return err
}

Prevention

When it happens

Trigger: PostProcess with archive set to "tar" (or filename ending in .tar*) and createTarArchive returning an error: an artifact file cannot be opened/stated, a tar header cannot be built, or a WriteHeader/Write to the tar stream fails.

Common situations: Artifact files vanished between build and post-process; disk full while writing the archive; permission problems on files produced by the builder; a file removed by a prior post-processor.

Related errors


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