{"record":{"id":"58e82b80fc977952","repo":"hashicorp/packer","slug":"cannot-specify-source-file-and-content","errorCode":null,"errorMessage":"Cannot specify source file AND content","messagePattern":"Cannot specify source file AND content","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"builder/file/config.go","lineNumber":18,"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},\n\t}, raws...)","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/builder/file/config.go#L1-L36","documentation":"Config validation error (sentinel var ErrContentSourceConflict) from the file builder's Prepare: both `content` (inline string) and `source` (a file to copy) are set, but the builder accepts exactly one source of data. Guarded by checking both fields are non-empty.","triggerScenarios":"Thrown at builder/file/config.go:18 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep `source` and remove `content` if you want to copy an existing file","Keep `content` and remove `source` if you want to write inline text"],"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"}