hashicorp/nomad · error

invalid variables limit: %v

Error message

invalid variables limit: %v

What it means

Quota resource blocks can cap Nomad Variables storage via a `variables` key interpreted as megabytes. parseStorageResource decodes the block and passes m["variables"] to parseQuotaMegabytes; any failure (non-numeric value, negative, bad unit) is wrapped as "invalid variables limit".

Source

Thrown at command/quota_apply.go:347

		return nil, nil
	case 1:
	default:
		return nil, errors.New("only one storage block is allowed")
	}
	block := storageBlocks.Items[0]
	valid := []string{"variables", "host_volumes"}
	if err := helper.CheckHCLKeys(block.Val, valid); err != nil {
		return nil, err
	}

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

	variablesLimit, err := parseQuotaMegabytes(m["variables"])
	if err != nil {
		return nil, fmt.Errorf("invalid variables limit: %v", err)
	}
	hostVolumesLimit, err := parseQuotaMegabytes(m["host_volumes"])
	if err != nil {
		return nil, fmt.Errorf("invalid host_volumes limit: %v", err)
	}

	return &api.QuotaStorageResources{
		VariablesMB:   variablesLimit,
		HostVolumesMB: hostVolumesLimit,
	}, nil
}

func parseQuotaMegabytes(raw any) (int, error) {
	switch val := raw.(type) {
	case string:
		b, err := humanize.ParseBytes(val)
		if err != nil {
			return 0, fmt.Errorf("could not parse value as bytes: %v", err)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set variables to a valid megabyte value, e.g. `variables = 1024` (or the unit form the parser accepts, like "1gb" if supported).
  2. Remove the variables key entirely if no Variables cap is needed (nil = unlimited).
  3. Check the wrapped %v error for the exact parse failure from parseQuotaMegabytes.
  4. Validate the spec with `nomad quota apply -parse-only`.

Example fix

// before
region_limit {
  variables = "ten gb"
}

// after
region_limit {
  variables = 10240
}
Defensive patterns

Strategy: validation

Validate before calling

const vars = /variables\s*=\s*(-?[\w".]+)/.exec(hcl);
if (vars) { const v = vars[1].replace(/"/g, ''); if (isNaN(Number(v)) || Number(v) < 0) throw new Error('variables limit must be a non-negative megabyte value'); }

Try / catch

try { parseQuotaSpec(file) } catch (e) { if (/invalid variables limit/.test(String(e))) { console.error('Fix the `variables` key in the storage/region_limit block (megabytes):', e.message); } throw e; }

Prevention

When it happens

Trigger: Setting `variables` in a region_limit (storage) block to a value parseQuotaMegabytes cannot handle — e.g. a string like "10gb" in the wrong unit form, a negative number, or a non-numeric type.

Common situations: Typos such as `variables = "-5"`, using units the parser doesn't accept, or quoting numbers in ways HCL decodes to the wrong type.

Related errors


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