hashicorp/nomad · error

resource: should be an object

Error message

resource: should be an object

What it means

The region_limit block's value must be an HCL ObjectType whose list holds the resource keys (cores, cpu, memory, etc.). parseQuotaResource returns this error when the region_limit value is not an object.

Source

Thrown at command/quota_apply.go:266

// parseQuotaResource parses the region_limit resources
func parseQuotaResource(result *api.QuotaResources, list *ast.ObjectList) error {
	list = list.Elem()
	if len(list.Items) == 0 {
		return nil
	}
	if len(list.Items) > 1 {
		return fmt.Errorf("only one 'region_limit' block allowed per limit")
	}

	// Get our resource object
	o := list.Items[0]

	// We need this later
	var listVal *ast.ObjectList
	if ot, ok := o.Val.(*ast.ObjectType); ok {
		listVal = ot.List
	} else {
		return fmt.Errorf("resource: should be an object")
	}

	// Check for invalid keys
	valid := []string{
		"cores",
		"cpu",
		"memory",
		"memory_max",
		"device",
		"storage",
		"node_pool",
	}
	if err := helper.CheckHCLKeys(listVal, valid); err != nil {
		return multierror.Prefix(err, "resources ->")
	}

	var m map[string]any
	if err := hcl.DecodeObject(&m, o.Val); err != nil {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Wrap resource keys in braces: `region_limit { cpu = 2000 memory_mb = 4096 }`.
  2. Only use supported keys inside the block (cores, cpu, memory, memory_mb, disk, disk_mb, and related fields) — invalid keys are rejected next.
  3. Validate with `nomad quota apply -parse-only` before submitting.

Example fix

// before
region_limit = 2000

// after
region_limit {
  cpu = 2000
  memory_mb = 4096
}
Defensive patterns

Strategy: validation

Validate before calling

const m = /region_limit\s*=\s*([^\{\s][^\n]*)/.exec(hcl);
if (m) throw new Error('region_limit must use block syntax: region_limit { ... }, not = ' + m[1]);

Prevention

When it happens

Trigger: Writing `region_limit = 2000` (scalar) or `region_limit = ["a","b"]` (list) instead of `region_limit { cpu = 2000 ... }`.

Common situations: Hand-editing quota files where the braces were dropped, or converting from JSON arrays incorrectly.

Related errors


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