hashicorp/nomad · error

limit should be an object

Error message

limit should be an object

What it means

Within a quota spec, each entry in the limits block must be an object (an HCL ObjectType). parseQuotaLimits walks each limit item; if the item's value is not an object, it cannot extract the inner list and returns this error.

Source

Thrown at command/quota_apply.go:231

		if err := hcl.DecodeObject(&m, o.Val); err != nil {
			return err
		}

		// Manually parse
		delete(m, "region_limit")

		// Decode the rest
		var limit api.QuotaLimit
		if err := mapstructure.WeakDecode(m, &limit); err != nil {
			return err
		}

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

		// Parse limits
		if o := listVal.Filter("region_limit"); len(o.Items) > 0 {
			limit.RegionLimit = new(api.QuotaResources)
			if err := parseQuotaResource(limit.RegionLimit, o); err != nil {
				return multierror.Prefix(err, "region_limit ->")
			}
		}

		*result = append(*result, &limit)
	}

	return nil
}

// parseQuotaResource parses the region_limit resources
func parseQuotaResource(result *api.QuotaResources, list *ast.ObjectList) error {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Define each limit as an object block: `limit { region = "global" ... }` inside the `limits` block.
  2. Remove or rename duplicate limit keys so HCL doesn't merge values into a non-object.
  3. Compare against a known-good quota spec example from Nomad docs.
  4. Validate the file with `nomad quota apply -parse-only` to catch structural mistakes early.

Example fix

// before
limits {
  limit = "global"
}

// after
limits {
  limit {
    region = "global"
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// each entry inside limits {} must be an object block
const limitBlock = /limits\s*\{([^}]*)\}/s.exec(hcl); 
if (limitBlock && /=\s*["'\d]/.test(limitBlock[1].replace(/#.*$/gm, ''))) throw new Error('limit entries must be objects: limit { ... }');

Prevention

When it happens

Trigger: Writing a limit as a scalar or list instead of an object block, e.g. `limit = "foo"` or a duplicated key that HCL merges into a non-object value inside `limits {}`.

Common situations: Copy-paste mistakes that leave a limit entry with `=` and a string instead of `{ }`, or redeclaring the same limit key causing HCL type conflicts.

Related errors


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