hashicorp/nomad · error

minimum count must be specified and non-negative

Error message

minimum count must be specified and non-negative

What it means

ScalingPolicy.Validate() requires the `min` count to be a non-negative integer. A negative Min (e.g. the -1 'unset' sentinel) appends this error to the multierror. Min defines the lower bound of the allowed task-group count range.

Source

Thrown at nomad/structs/structs.go:6452

	// Check policy type and target
	if p.Type == "" {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("missing scaling policy type"))
	} else {
		mErr.Errors = append(mErr.Errors, p.validateType().Errors...)
	}

	// Check Min and Max
	if p.Max < 0 {
		mErr.Errors = append(mErr.Errors,
			fmt.Errorf("maximum count must be specified and non-negative"))
	} else if p.Max < p.Min {
		mErr.Errors = append(mErr.Errors,
			fmt.Errorf("maximum count must not be less than minimum count"))
	}

	if p.Min < 0 {
		mErr.Errors = append(mErr.Errors,
			fmt.Errorf("minimum count must be specified and non-negative"))
	}

	return mErr.ErrorOrNil()
}

func (p *ScalingPolicy) validateTargetHorizontal() (mErr multierror.Error) {
	if len(p.Target) == 0 {
		// This is probably not a Nomad horizontal policy
		return
	}

	// Nomad horizontal policies should have Namespace, Job and TaskGroup
	if p.Target[ScalingTargetNamespace] == "" {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("missing target namespace"))
	}
	if p.Target[ScalingTargetJob] == "" {
		mErr.Errors = append(mErr.Errors, fmt.Errorf("missing target job"))
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set `min` to zero or a positive integer in the scaling block.
  2. If you want no effective minimum, use `min = 0`, not a negative number.
  3. Re-run `nomad job validate` to confirm the whole policy passes.

Example fix

// before
scaling {
  min = -1
  max = 10
}
// after
scaling {
  min = 0
  max = 10
}
Defensive patterns

Strategy: validation

Validate before calling

if policy.Min < 0 {
	return fmt.Errorf("scaling policy min must be non-negative; use 0 for no minimum")
}

Prevention

When it happens

Trigger: Submitting a job with `scaling { min = -1 }`, or constructing a ScalingPolicy via the API with a negative Min left from a default value.

Common situations: Omitting min in generated policy JSON where the struct default is negative; using -1 to mean 'no minimum' in custom tooling; typos in HCL.

Related errors


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