{"record":{"id":"14b9ea4abfc89068","repo":"hashicorp/packer","slug":"target-required","errorCode":null,"errorMessage":"target required","messagePattern":"target required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"builder/file/config.go","lineNumber":17,"sourceCode":"// Copyright IBM Corp. 2024, 2025\n// SPDX-License-Identifier: BUSL-1.1\n\n//go:generate packer-sdc mapstructure-to-hcl2 -type Config\n\npackage file\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/hashicorp/packer-plugin-sdk/common\"\n\tpackersdk \"github.com/hashicorp/packer-plugin-sdk/packer\"\n\t\"github.com/hashicorp/packer-plugin-sdk/template/config\"\n\t\"github.com/hashicorp/packer-plugin-sdk/template/interpolate\"\n)\n\nvar ErrTargetRequired = fmt.Errorf(\"target required\")\nvar ErrContentSourceConflict = fmt.Errorf(\"Cannot specify source file AND content\")\n\ntype Config struct {\n\tcommon.PackerConfig `mapstructure:\",squash\"`\n\n\tSource  string `mapstructure:\"source\"`\n\tTarget  string `mapstructure:\"target\"`\n\tContent string `mapstructure:\"content\"`\n}\n\nfunc (c *Config) Prepare(raws ...interface{}) ([]string, error) {\n\twarnings := []string{}\n\n\terr := config.Decode(c, &config.DecodeOpts{\n\t\tInterpolate: true,\n\t\tInterpolateFilter: &interpolate.RenderFilter{\n\t\t\tExclude: []string{},\n\t\t},","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/builder/file/config.go#L1-L35","documentation":"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 == \"\".","triggerScenarios":"Thrown at builder/file/config.go:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}