hashicorp/nomad · error
%s must be integer; got (%T) %[2]v
Error message
%s must be integer; got (%T) %[2]v
What it means
parseVariableSpecImpl maps raw HCL-decoded values onto api.Variable fields. `create_index` and `modify_index` must decode as Go ints; if the HCL file supplies them as another type (string, float, etc.) the function returns `%s must be integer; got (%T) %v`, naming the offending key and its actual Go type/value.
Source
Thrown at command/var_put.go:516
// Check for invalid keys
valid := []string{
"namespace",
"path",
"create_index",
"modify_index",
"create_time",
"modify_time",
"items",
}
if err := helper.CheckHCLKeys(list, valid); err != nil {
return err
}
for _, index := range []string{"create_index", "modify_index"} {
if value, ok := m[index]; ok {
vInt, ok := value.(int)
if !ok {
return fmt.Errorf("%s must be integer; got (%T) %[2]v", index, value)
}
idx := uint64(vInt)
n := strings.ReplaceAll(
cases.Title(language.English).String(
strings.ReplaceAll(index, "_", " "),
), " ", "")
m[n] = idx
delete(m, index)
}
}
for _, index := range []string{"create_time", "modify_time"} {
if value, ok := m[index]; ok {
vInt, ok := value.(int)
if !ok {
return fmt.Errorf("%s must be a int64; got a (%T) %[2]v", index, value)
}
n := strings.ReplaceAll(View on GitHub (pinned to 482b49bf1a)
Solutions
- Remove `create_index`/`modify_index` from the spec entirely — the server manages these fields.
- If they must be present, write them as bare integers: `create_index = 42`, no quotes or decimals.
- Regenerate the spec from `nomad var init` instead of editing API output.
Example fix
// before create_index = "42" // after create_index = 42
Defensive patterns
Strategy: validation
Validate before calling
# strip server-managed fields from the spec before submitting
grep -E '^(create_index|modify_index)\s*=' spec.hcl && { echo 'remove create_index/modify_index from spec' >&2; exit 1; } || true Try / catch
if err := run(); err != nil {
var terr *fmt.Errorf // message contains 'must be integer'
if strings.Contains(err.Error(), "must be integer") {
log.Fatalf("spec index field wrong type: %v", err)
}
log.Fatal(err)
} Prevention
- Never copy server-managed fields (create_index, modify_index) from API output into specs.
- If present, write them as bare integers, never quoted strings or floats.
- Build specs from the `nomad var init` template, which omits these fields.
When it happens
Trigger: An .hcl spec containing `create_index = "12"` or a non-integer literal (e.g. `12.0`) for `create_index`/`modify_index`, typically because the value was copy-pasted from `nomad var read` output in JSON form where indexes appear as quoted or large numbers.
Common situations: Round-tripping a variable read from the API into an HCL spec without removing read-only fields (CreateIndex/ModifyIndex are server-managed and should generally be omitted from specs).
Related errors
- %s must be a int64; got a (%T) %[2]v
- <combined HCL diagnostics from str.String()>
- invalid variables limit: %v
- invalid capacity: %v
- invalid capacity_min: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/c74ce1756124c7a1.
Report an issue: GitHub.