{"record":{"id":"4b54c4e3d36f82b5","repo":"hashicorp/nomad","slug":"no-ltarget-provided-but-is-required","errorCode":null,"errorMessage":"No LTarget provided but is required","messagePattern":"No LTarget provided but is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":10228,"sourceCode":"\tcase ConstraintVersion:\n\t\tif _, err := version.NewConstraint(a.RTarget); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Version affinity is invalid: %v\", err))\n\t\t}\n\tcase ConstraintSemver:\n\t\tif _, err := semver.NewConstraint(a.RTarget); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Semver affinity is invalid: %v\", err))\n\t\t}\n\tcase \"=\", \"==\", \"is\", \"!=\", \"not\", \"<\", \"<=\", \">\", \">=\":\n\t\tif a.RTarget == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Operator %q requires an RTarget\", a.Operand))\n\t\t}\n\tdefault:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Unknown affinity operator %q\", a.Operand))\n\t}\n\n\t// Ensure we have an LTarget\n\tif a.LTarget == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"No LTarget provided but is required\"))\n\t}\n\n\t// Ensure that weight is between -100 and 100, and not zero\n\tif a.Weight == 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Affinity weight cannot be zero\"))\n\t}\n\n\tif a.Weight > 100 || a.Weight < -100 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Affinity weight must be within the range [-100,100]\"))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// DiffID fulfills the DiffableWithID interface.\nfunc (a *Affinity) DiffID() string {\n\treturn a.String()\n}","sourceCodeStart":10210,"sourceCodeEnd":10246,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L10210-L10246","documentation":"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'.","triggerScenarios":"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.","commonSituations":"HCL templates where the attribute variable failed to render, hand-edited jobs where attribute was deleted, or SDK/programmatic job construction omitting LTarget.","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."],"exampleFix":"// before\naffinity {\n  operator = \"is\"\n  value    = \"dc1\"\n}\n// after\naffinity {\n  attribute = \"${node.datacenter}\"\n  operator  = \"is\"\n  value    = \"dc1\"\n}","handlingStrategy":"validation","validationCode":"if a.LTarget == \"\" { return errors.New(\"affinity requires attribute (LTarget)\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set attribute on affinity blocks","Guard templated HCL so empty attribute variables skip the affinity block","Use nomad job validate before submit"],"tags":["nomad","affinity","job-spec","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}