hashicorp/nomad · error

no attribute provided but is required by operator

Error message

no attribute provided but is required by operator

What it means

Constraint.Validate() requires an LTarget (the attribute/expression being compared) for all operands that need one (most operators except distinct_hosts, distinct_property with no target, etc.). When Operand demands an LTarget but c.LTarget is the empty string, this error is appended to the validation multierror.

Source

Thrown at nomad/structs/structs.go:10110

			}
		}
	case ConstraintAttributeIsSet, ConstraintAttributeIsNotSet:
		if c.RTarget != "" {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Operator %q does not support an RTarget", c.Operand))
		}
	case "=", "==", "is", "!=", "not", "<", "<=", ">", ">=":
		if c.RTarget == "" {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Operator %q requires an RTarget", c.Operand))
		}
	default:
		mErr.Errors = append(mErr.Errors, fmt.Errorf("Unknown constraint type %q", c.Operand))
	}

	// If the constraint must have a "LTarget" (attribute in the job spec), then
	// ensure it is not an empty string and is valid.
	if requireLtarget {
		if c.LTarget == "" {
			mErr.Errors = append(mErr.Errors, errors.New("no attribute provided but is required by operator"))
		} else {
			if err := validateConstraintAttribute(c.LTarget); err != nil {
				mErr.Errors = append(mErr.Errors, err)
			}
		}

	}

	return mErr.ErrorOrNil()
}

// DiffID fulfills the DiffableWithID interface.
func (c *Constraint) DiffID() string {
	return c.String()
}

type Constraints []*Constraint

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Add the required attribute/LTarget to the constraint, e.g. attribute = "${node.class}".
  2. If you intended a node-wide constraint like distinct_hosts, use operator "distinct_hosts" with no attribute, or set the proper attribute.
  3. Verify the attribute expression syntax (must be like ${node.attr} or a literal) so validateConstraintAttribute doesn't add further errors.
  4. Run `nomad job validate` before submitting.

Example fix

// before
constraint {
  operator = "regexp"
  value    = "r[1-2]"
}
// after
constraint {
  attribute = "${meta.rack}"
  operator  = "regexp"
  value     = "r[1-2]"
}
Defensive patterns

Strategy: validation

Validate before calling

func validateConstraintLTarget(c *structs.Constraint) error {
	needsTarget := c.Operand != "distinct_hosts" && c.Operand != ""
	if needsTarget && c.LTarget == "" {
		return fmt.Errorf("constraint with operand %q requires an attribute (LTarget)", c.Operand)
	}
	return nil
}

Type guard

func constraintHasAttribute(c *structs.Constraint) bool { return c != nil && c.LTarget != "" }

Prevention

When it happens

Trigger: Submitting a constraint with an operator but no attribute, e.g. `constraint { operator = "regexp"; value = "web-.*" }` without attribute, or Constraint{Operand: "=", RTarget: "x"} in Go.

Common situations: Copy-pasting constraint examples and dropping the attribute line; writing distinct_hosts-style constraints then switching the operator to something that needs a target; programmatic generation where LTarget is filled conditionally and the condition failed.

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


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/3d47d51855e829a2. Report an issue: GitHub.