hashicorp/nomad · error
Task can only ask for 'cpu' or 'cores' resource, not both.
Error message
Task can only ask for 'cpu' or 'cores' resource, not both.
What it means
Appended by Resources.Validate when a task resource block sets both CPU (MHz) and Cores. Nomad permits either the legacy cpu-based accounting or the newer cores-based one, never both on the same task.
Source
Thrown at nomad/structs/structs.go:2424
}
}
// DiskInBytes returns the amount of disk resources in bytes.
func (r *Resources) DiskInBytes() int64 {
return int64(r.DiskMB * BytesInMegabyte)
}
const (
// MemoryNoLimit is a sentinel value indicating there is no upper hard
// memory limit
MemoryNoLimit = -1
)
func (r *Resources) Validate() error {
var mErr multierror.Error
if r.Cores > 0 && r.CPU > 0 {
mErr.Errors = append(mErr.Errors, errors.New("Task can only ask for 'cpu' or 'cores' resource, not both."))
}
if r.Cores < 0 {
mErr.Errors = append(mErr.Errors, fmt.Errorf("cores value (%d) cannot be negative", r.Cores))
}
if err := r.MeetsMinResources(); err != nil {
mErr.Errors = append(mErr.Errors, err)
}
// Ensure the task isn't asking for disk resources
if r.DiskMB > 0 {
mErr.Errors = append(mErr.Errors, errors.New("Task can't ask for disk resources, they have to be specified at the task group level."))
}
// Ensure devices are valid
devices := set.New[string](len(r.Devices))
for i, d := range r.Devices {View on GitHub (pinned to 482b49bf1a)
Solutions
- Remove the cpu field and keep cores (recommended for whole-core granularity)
- Or remove cores and keep cpu (MHz) for finer-grained sizing
Example fix
// before
resources {
cpu = 2000
cores = 2
memory = 1024
}
// after
resources {
cores = 2
memory = 1024
} Defensive patterns
Strategy: validation
Validate before calling
function validateCpuExclusive(resources) {
if ((resources.cores ?? 0) > 0 && (resources.cpu ?? 0) > 0) {
throw new Error("task resources: set either cpu (MHz) or cores, not both");
}
} Type guard
function hasValidCpuSpec(r) { return !((r.cores ?? 0) > 0 && (r.cpu ?? 0) > 0); } Try / catch
try {
await nomad.jobs.validate(job);
} catch (e) {
if (e.message.includes("'cpu' or 'cores' resource, not both")) {
console.error("Pick one CPU sizing field per task");
} else throw e;
} Prevention
- Standardize on one CPU sizing convention (cores for whole-core, cpu for MHz) org-wide
- Watch for template layering that adds cores on top of a cpu default
- Keep base resource templates with only one CPU field set
When it happens
Trigger: A task resources block (or Resources struct) with cores > 0 and cpu > 0 simultaneously during job validation.
Common situations: Jobs written after Nomad 1.1 introduced cores, where a base template set cpu and the operator added cores; tooling merging resource defaults with overrides.
Related errors
- Task can't ask for disk resources, they have to be specified
- minimum CPU value is %d; got %d
- ErrConnectRequireOneNetwork
- ErrConnectInvalidNetworkMode
- service.port must be set for mesh gateway service
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/2450f55f35f25e5e.
Report an issue: GitHub.