hashicorp/packer · error

too many values, 1 needed: %v

Error message

too many values, 1 needed: %v

What it means

The `timestamp()` HCL2 function takes at most one optional argument (a Go time layout string). The cty function framework already enforces arity via VarParam, but this defensive check in the Impl returns this error if more than one argument reaches it, echoing the offending values.

Source

Thrown at hcl2template/function/datetime.go:55

// using RFC 3339 "Date and Time format" syntax, and so timestamp returns a
// string in this format.
func Timestamp() (cty.Value, error) {
	return TimestampFunc.Call([]cty.Value{})
}

// LegacyIsotimeFunc constructs a function that returns a string representation
// of the current date and time using the Go language datetime formatting syntax.
var LegacyIsotimeFunc = function.New(&function.Spec{
	Params: []function.Parameter{},
	VarParam: &function.Parameter{
		Name: "format",
		Type: cty.String,
	},
	Type:         function.StaticReturnType(cty.String),
	RefineResult: refineNotNull,
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		if len(args) > 1 {
			return cty.StringVal(""), fmt.Errorf("too many values, 1 needed: %v", args)
		}
		if len(args) == 0 {
			return cty.StringVal(initTime.Format(time.RFC3339)), nil
		}
		format := args[0].AsString()
		return cty.StringVal(initTime.Format(format)), nil
	},
})

// LegacyStrftimeFunc constructs a function that returns a string representation
// of the current date and time using the Go language strftime datetime formatting syntax.
var LegacyStrftimeFunc = function.New(&function.Spec{
	Params: []function.Parameter{},
	VarParam: &function.Parameter{
		Name: "format",
		Type: cty.String,
	},
	Type:         function.StaticReturnType(cty.String),

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Pass at most one argument: `timestamp()` for RFC3339 now, or `timestamp("2006-01-02T15:04:05Z07:00")` for a custom Go layout
  2. Split formatting: use `timestamp()` and format downstream if you need multiple pieces of data
  3. Remove extra arguments in the template

Example fix

// before (invalid)
timestamp = timestamp("2006-01-02", "UTC")
// after
timestamp = timestamp("2006-01-02")
Defensive patterns

Strategy: validation

Validate before calling

// check arity before use (HCL has no guard; validate via packer console)
// $ packer console
// > timestamp()
// > timestamp("2006-01-02")

Try / catch

null

Prevention

When it happens

Trigger: Calling `timestamp(a, b)` in an HCL2 template — e.g. `timestamp("2006-01-02", "extra")` — if arity checking is bypassed or the check is the active guard against extra args.

Common situations: Copy-pasting a strftime-style call with two arguments, or misremembering that timestamp accepts a format plus something else; normally caught earlier by HCL arity validation.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/dd6b6a29a979bf11. Report an issue: GitHub.