hashicorp/nomad · error

Set contains operators require an RTarget

Error message

Set contains operators require an RTarget

What it means

An affinity (or set-contains constraint) uses operand set_contains_all / set_contains_any / set_contains, but its RTarget — the value that must (or any/all of whose elements must) be contained in the attribute's set — is empty. Affinity validation rejects it.

Source

Thrown at nomad/structs/structs.go:10204

		Weight:  a.Weight,
	}
}

func (a *Affinity) String() string {
	return fmt.Sprintf("%s %s %s %v", a.LTarget, a.Operand, a.RTarget, a.Weight)
}

func (a *Affinity) Validate() error {
	var mErr multierror.Error
	if a.Operand == "" {
		mErr.Errors = append(mErr.Errors, errors.New("Missing affinity operand"))
	}

	// Perform additional validation based on operand
	switch a.Operand {
	case ConstraintSetContainsAll, ConstraintSetContainsAny, ConstraintSetContains:
		if a.RTarget == "" {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Set contains operators require an RTarget"))
		}
	case ConstraintRegex:
		if _, err := regexp.Compile(a.RTarget); err != nil {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Regular expression failed to compile: %v", err))
		}
	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:

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Supply the required value field, e.g. value = "gpu,fast".
  2. Verify templating renders a non-empty value.
  3. If the intent was not set matching, pick a comparison operator that fits (but note set-contains requires a target).

Example fix

// before
affinity {
  attribute = "${meta.node_tags}"
  operand   = "set_contains_all"
  weight    = 50
}
// after
affinity {
  attribute = "${meta.node_tags}"
  operand   = "set_contains_all"
  value     = "gpu,highmem"
  weight    = 50
}
Defensive patterns

Strategy: validation

Validate before calling

func affinityTargetAllowed(operand, rtarget string) bool {
  switch operand {
  case "set_contains_all", "set_contains_any", "set_contains":
    return rtarget != ""
  default:
    return true
  }
}

Try / catch

if slices.Contains([]string{"set_contains", "set_contains_any", "set_contains_all"}, operand) && rtarget == "" {
  return fmt.Errorf("%s requires a value", operand)
}

Prevention

When it happens

Trigger: Submitting an affinity like affinity { attribute = "${meta.tags}" operand = "set_contains_all" } with no value/RTarget set.

Common situations: Templated affinity generation where the interpolated value variable was empty; copy-paste of an affinity template with the value line deleted; confusion between the weight/attribute fields and the required value.

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/29575080b42ca241. Report an issue: GitHub.