hashicorp/nomad · error
No LTarget provided but is required
Error message
No LTarget provided but is required
What it means
Affinity.Validate() requires an LTarget — the left-hand attribute/expression the affinity is evaluated against (e.g. "${node.datacenter}" or "attr.meta.foo"). If a.LTarget is empty, Nomad rejects the affinity with 'No LTarget provided but is required'.
Source
Thrown at nomad/structs/structs.go:10228
case ConstraintVersion:
if _, err := version.NewConstraint(a.RTarget); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Version affinity is invalid: %v", err))
}
case ConstraintSemver:
if _, err := semver.NewConstraint(a.RTarget); err != nil {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Semver affinity is invalid: %v", err))
}
case "=", "==", "is", "!=", "not", "<", "<=", ">", ">=":
if a.RTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Operator %q requires an RTarget", a.Operand))
}
default:
mErr.Errors = append(mErr.Errors, fmt.Errorf("Unknown affinity operator %q", a.Operand))
}
// Ensure we have an LTarget
if a.LTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("No LTarget provided but is required"))
}
// Ensure that weight is between -100 and 100, and not zero
if a.Weight == 0 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Affinity weight cannot be zero"))
}
if a.Weight > 100 || a.Weight < -100 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Affinity weight must be within the range [-100,100]"))
}
return mErr.ErrorOrNil()
}
// DiffID fulfills the DiffableWithID interface.
func (a *Affinity) DiffID() string {
return a.String()
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Set the attribute field on the affinity, e.g. attribute = "${node.datacenter}".
- Remove the affinity block entirely if it is not needed.
- In generated jobs, skip emitting affinity blocks whose attribute is empty.
Example fix
// before
affinity {
operator = "is"
value = "dc1"
}
// after
affinity {
attribute = "${node.datacenter}"
operator = "is"
value = "dc1"
} Defensive patterns
Strategy: validation
Validate before calling
if a.LTarget == "" { return errors.New("affinity requires attribute (LTarget)") } Prevention
- Always set attribute on affinity blocks
- Guard templated HCL so empty attribute variables skip the affinity block
- Use nomad job validate before submit
When it happens
Trigger: An affinity block or API payload with no attribute (LTarget) set while other fields (operator/weight) are present; occurs at job registration via nomad job run or POST /v1/jobs.
Common situations: HCL templates where the attribute variable failed to render, hand-edited jobs where attribute was deleted, or SDK/programmatic job construction omitting LTarget.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Semver affinity is invalid: %v
- Unknown affinity operator %q
- Affinity weight cannot be zero
- Affinity weight must be within the range [-100,100]
- Disconnect cannot be configured with both lost_after and sto
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/4b54c4e3d36f82b5.
Report an issue: GitHub.