hashicorp/packer · error

Cannot specify source file AND content

Error message

Cannot specify source file AND content

What it means

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.

Source

Thrown at builder/file/config.go:18

// 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{},
		},
	}, raws...)

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Keep `source` and remove `content` if you want to copy an existing file
  2. Keep `content` and remove `source` if you want to write inline text
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at builder/file/config.go:18 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/58e82b80fc977952. Report an issue: GitHub.