hashicorp/nomad · error

only one name may be specified

Error message

only one name may be specified

What it means

Each device entry in a quota spec must have exactly one key (the device name). If an entry has more than one key — e.g. `device "a" "b" { ... }` — parseDeviceResource rejects it with "only one name may be specified", prefixed `resources, device[N]->`. This mirrors the same check Nomad applies to device blocks in job resources.

Source

Thrown at command/quota_apply.go:382

		if err != nil {
			return 0, fmt.Errorf("could not parse value as bytes: %v", err)
		}
		return int(b >> 20), nil
	case int:
		return val, nil
	case nil:
		return 0, nil
	default:
		return 0, fmt.Errorf("invalid type %T", raw)
	}
}

func parseDeviceResource(result *[]*api.RequestedDevice, list *ast.ObjectList) error {
	for idx, o := range list.Items {
		if l := len(o.Keys); l == 0 {
			return multierror.Prefix(fmt.Errorf("missing device name"), fmt.Sprintf("resources, device[%d]->", idx))
		} else if l > 1 {
			return multierror.Prefix(fmt.Errorf("only one name may be specified"), fmt.Sprintf("resources, device[%d]->", idx))
		}

		name := o.Keys[0].Token.Value().(string)

		// Check for invalid keys
		valid := []string{
			"name",
			"count",
		}
		if err := helper.CheckHCLKeys(o.Val, valid); err != nil {
			return err
		}

		// Set the name
		var device api.RequestedDevice
		device.Name = name

		var m map[string]any

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Keep one name per device block and split into separate blocks for multiple devices: `device "a" {}` and `device "b" {}`.
  2. Use the device[N] prefix in the error to find the offending entry.
  3. Reformat with hclfmt and re-read the stanza to spot duplicated keys.
  4. Validate against Nomad's quota example files.

Example fix

// before
device "nvidia/gpu" "amd/gpu" {
  count = 1
}
// after
device "nvidia/gpu" {
  count = 1
}
device "amd/gpu" {
  count = 1
}
Defensive patterns

Strategy: validation

Validate before calling

for idx, item := range deviceList.Items {
    if len(item.Keys) > 1 {
        return fmt.Errorf("resources, device[%d]-> only one name may be specified", idx)
    }
}

Type guard

func hasExactlyOneKey(item *hclast.ObjectItem) bool {
    return item != nil && len(item.Keys) == 1
}

Prevention

When it happens

Trigger: A quota file declares a device stanza with multiple labels/keys, such as `device "gpu" "tpu" { }` or a malformed HCL key list on one entry.

Common situations: Accidentally specifying two device names in one block instead of two separate device blocks; editor auto-completion duplicating a quoted name; merging two blocks and concatenating their keys.

Related errors


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