hashicorp/packer · error
failed to get current working directory for Packer SBOM: %s
Error message
failed to get current working directory for Packer SBOM: %s
What it means
The internal SBOM provisioner delegates to the hcp-sbom provisioner and first needs a temp file created in the current working directory. If os.Getwd() fails (e.g. the working directory was deleted or is unreadable), Provision returns this wrapped error.
Source
Thrown at packer/provisioner.go:358
// Try to delegate to inner provisioner if it implements FlatConfig
if fc, ok := p.Provisioner.(interface{ FlatConfig() interface{} }); ok {
return fc.FlatConfig()
}
return nil
}
func (p *SBOMInternalProvisioner) Prepare(raws ...interface{}) error {
return p.Provisioner.Prepare(raws...)
}
func (p *SBOMInternalProvisioner) Provision(
ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator,
generatedData map[string]interface{},
) error {
// Original implementation - all logic now in hcp-sbom provisioner
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get current working directory for Packer SBOM: %s", err)
}
tmpFile, err := os.CreateTemp(cwd, "packer-sbom-*.json")
if err != nil {
return fmt.Errorf("failed to create internal temporary file for Packer SBOM: %s", err)
}
tmpFileName := tmpFile.Name()
if err = tmpFile.Close(); err != nil {
return fmt.Errorf("failed to close temporary file for Packer SBOM %s: %s", tmpFileName, err)
}
defer func(name string) {
fileRemoveErr := os.Remove(name)
if fileRemoveErr != nil {
log.Printf("Error removing SBOM temporary file %s: %s", name, fileRemoveErr)
}
}(tmpFile.Name())View on GitHub (pinned to eb36e3c3e4)
Solutions
- Re-run Packer from an existing, writable directory.
- Fix the preceding pipeline step that removed or recreated the working directory.
- Ensure the container/CI job's working directory exists and is readable before invoking packer.
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Getwd(); err != nil {
return fmt.Errorf("cannot run SBOM provisioner: working directory unavailable: %w", err)
} Try / catch
if err := p.Provision(ctx, ui, comm, data); err != nil {
if strings.Contains(err.Error(), "current working directory for Packer SBOM") {
// restart packer from an existing directory
}
} Prevention
- Launch packer from a directory that earlier pipeline steps don't delete or recreate.
- Ensure container WORKDIR exists for the process lifetime.
- Avoid cd into ephemeral temp dirs cleaned mid-run.
When it happens
Trigger: Calling Provision on the built-in SBOM provisioner (packer/provisioner.go:Provision) when os.Getwd() returns an error — typically because the process's current working directory no longer exists or lacks permissions.
Common situations: Running Packer from a directory deleted/recreated by a prior build step; running in a container whose WORKDIR was removed; a CI job that cd's into a temp dir which is cleaned mid-run.
Related errors
- failed to get source: %w
- failed to create internal temporary file for Packer SBOM: %s
- failed to close temporary file for Packer SBOM %s: %s
- failed to open Packer SBOM file %q: %s
- write SBOM %q: %w
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/2ed4a4ad50462a9d.
Report an issue: GitHub.