hashicorp/terraform · error
exactly one argument is required
Error message
exactly one argument is required
What it means
encode_tfvars builtin guard: the function schema declares exactly one parameter, so the language runtime should reject zero-arg calls before this code runs. The check is purely defensive robustness; reaching it implies the caller bypassed schema validation.
Solutions
- Call encode_tfvars through normal HCL so the schema enforces arity (encode_tfvars(var.obj)).
- If calling programmatically, supply exactly one argument matching the declared parameter.
- Ensure the function's declared parameter count matches when wrapping/monkey-patching.
Example fix
// before (programmatic misuse)
encodeTfvarsFunc([]cty.Value{})
// after
encodeTfvarsFunc([]cty.Value{cty.ObjectVal(map[string]cty.Value{"x": cty.StringVal("y")})}) Defensive patterns
Strategy: validation
Validate before calling
// Programmatic callers: enforce arity before dispatch
if len(args) != 1 { return cty.NilVal, fmt.Errorf("encode_tfvars takes exactly 1 arg") } Type guard
func encodeTfvarsArityOK(args []cty.Value) bool { return len(args) == 1 } Prevention
- Invoke encode_tfvars through HCL so the schema enforces arity.
- Keep the in-body guard and the schema ParameterTypes in sync when editing.
- Cover direct-call paths in unit tests.
When it happens
Trigger: encodeTfvarsFunc invoked with len(args) == 0: a direct programmatic call to the function without args (not via HCL), or a bug in the function dispatcher that skipped schema-based arity checks.
Common situations: Internal testing invoking the function directly; a regression in the function dispatcher; experimental code path bypassing the schema layer.
Related errors
- argument must be a string
- action schema not found for action
- Can't serialize backend configuration as JSON
- error writing state
- Failed to marshal state to json
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/213672c840b8a221.
Report an issue: GitHub.
Appendix: source
Thrown at internal/builtin/providers/terraform/functions.go:32
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
)
var functions = map[string]func([]cty.Value) (cty.Value, error){
"encode_tfvars": encodeTfvarsFunc,
"decode_tfvars": decodeTfvarsFunc,
"encode_expr": encodeExprFunc,
}
func encodeTfvarsFunc(args []cty.Value) (cty.Value, error) {
// These error checks should not be hit in practice because the language
// runtime should check them before calling, so this is just for robustness
// and completeness.
if len(args) > 1 {
return cty.NilVal, function.NewArgErrorf(1, "too many arguments; only one expected")
}
if len(args) == 0 {
return cty.NilVal, fmt.Errorf("exactly one argument is required")
}
v := args[0]
ty := v.Type()
if v.IsNull() {
// Our functions schema does not say we allow null values, so we should
// not get to this error message if the caller respects the schema.
return cty.NilVal, function.NewArgErrorf(1, "cannot encode a null value in tfvars syntax")
}
if !v.IsWhollyKnown() {
return cty.UnknownVal(cty.String).RefineNotNull(), nil
}
var keys []string
switch {
case ty.IsObjectType():
atys := ty.AttributeTypes()View on GitHub (pinned to d32a084675)