hashicorp/packer · error
target required
Error message
target required
What it means
Config validation error (sentinel var ErrTargetRequired) from the file builder's Prepare: the `target` field, which tells the builder where to write the output file, is empty or missing. Guarded by checking c.Target == "".
Source
Thrown at builder/file/config.go:17
// Copyright IBM Corp. 2024, 2025
// SPDX-License-Identifier: BUSL-1.1
//go:generate packer-sdc mapstructure-to-hcl2 -type Config
package file
import (
"fmt"
"github.com/hashicorp/packer-plugin-sdk/common"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
)
var ErrTargetRequired = fmt.Errorf("target required")
var ErrContentSourceConflict = fmt.Errorf("Cannot specify source file AND content")
type Config struct {
common.PackerConfig `mapstructure:",squash"`
Source string `mapstructure:"source"`
Target string `mapstructure:"target"`
Content string `mapstructure:"content"`
}
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
warnings := []string{}
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},View on GitHub (pinned to eb36e3c3e4)
Solutions
- Add a `target` argument to the file builder stanza, e.g. target = "output.txt"
- Use Packer interpolations in target such as {{ .BuildName }} if you need dynamic names
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at builder/file/config.go:17 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/14b9ea4abfc89068.
Report an issue: GitHub.