{"record":{"id":"c517b4add9c25334","repo":"hashicorp/packer","slug":"failed-to-create-internal-temporary-file-for-packe","errorCode":null,"errorMessage":"failed to create internal temporary file for Packer SBOM: %s","messagePattern":"failed to create internal temporary file for Packer SBOM: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/provisioner.go","lineNumber":363,"sourceCode":"}\n\nfunc (p *SBOMInternalProvisioner) Prepare(raws ...interface{}) error {\n\treturn p.Provisioner.Prepare(raws...)\n}\n\nfunc (p *SBOMInternalProvisioner) Provision(\n\tctx context.Context, ui packersdk.Ui, comm packersdk.Communicator,\n\tgeneratedData map[string]interface{},\n) error {\n\t// Original implementation - all logic now in hcp-sbom provisioner\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current working directory for Packer SBOM: %s\", err)\n\t}\n\n\ttmpFile, err := os.CreateTemp(cwd, \"packer-sbom-*.json\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create internal temporary file for Packer SBOM: %s\", err)\n\t}\n\n\ttmpFileName := tmpFile.Name()\n\tif err = tmpFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"failed to close temporary file for Packer SBOM %s: %s\", tmpFileName, err)\n\t}\n\n\tdefer func(name string) {\n\t\tfileRemoveErr := os.Remove(name)\n\t\tif fileRemoveErr != nil {\n\t\t\tlog.Printf(\"Error removing SBOM temporary file %s: %s\", name, fileRemoveErr)\n\t\t}\n\t}(tmpFile.Name())\n\n\tgeneratedData[\"dst\"] = tmpFile.Name()\n\n\terr = p.Provisioner.Provision(ctx, ui, comm, generatedData)\n\tif err != nil {","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/provisioner.go#L345-L381","documentation":"After determining the working directory, the internal SBOM provisioner creates a temporary file packer-sbom-*.json there via os.CreateTemp. If file creation fails (permissions, read-only filesystem, no space), Provision returns this wrapped error.","triggerScenarios":"Calling Provision on the built-in SBOM provisioner when os.CreateTemp(cwd, \"packer-sbom-*.json\") errors — e.g. the cwd is read-only, owned by another user, or the disk is full.","commonSituations":"Running Packer from a read-only mounted directory; insufficient write permissions after privilege changes; disk-quota exhaustion on CI runners.","solutions":["Run packer from a writable directory.","Fix permissions on the working directory (chmod/chown) or free disk space.","Ensure the build pipeline runs packer with a user allowed to create files in the cwd."],"exampleFix":"// before: running from a read-only checkout\n$ cd /mnt/ro/repo && packer build .\n// error: failed to create internal temporary file for Packer SBOM\n// after\n$ cd /mnt/rw/build && packer build /mnt/ro/repo/template.pkr.hcl","handlingStrategy":"validation","validationCode":"cwd, err := os.Getwd()\nif err == nil {\n  f, err := os.CreateTemp(cwd, \"write-test-*\")\n  if err == nil { f.Close(); os.Remove(f.Name()) } else { /* cwd not writable */ }\n}","typeGuard":null,"tryCatchPattern":"if err := p.Provision(ctx, ui, comm, data); err != nil {\n  if strings.Contains(err.Error(), \"internal temporary file for Packer SBOM\") {\n    // fix permissions/space or run from a writable dir\n  }\n}","preventionTips":["Run packer from a writable directory, not read-only mounts.","Check disk quota/space before builds.","Ensure the packer process user can write to the cwd."],"tags":["filesystem","sbom","temp-file"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}