{"record":{"id":"0ccc7f147c2ed140","repo":"hashicorp/nomad","slug":"namespace-q-using-non-existent-quota-q","errorCode":null,"errorMessage":"namespace %q using non-existent quota %q","messagePattern":"namespace %q using non-existent quota %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":7098,"sourceCode":"\tif existing != nil {\n\t\texist := existing.(*structs.Namespace)\n\t\tns.CreateIndex = exist.CreateIndex\n\t\tns.ModifyIndex = index\n\n\t\t// Grab the old quota on the namespace\n\t\toldQuota = exist.Quota\n\t} else {\n\t\tns.CreateIndex = index\n\t\tns.ModifyIndex = index\n\t}\n\n\t// Validate that the quota on the new namespace exists\n\tif ns.Quota != \"\" {\n\t\texists, err := s.quotaSpecExists(txn, ns.Quota)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"looking up namespace quota %q failed: %v\", ns.Quota, err)\n\t\t} else if !exists {\n\t\t\treturn fmt.Errorf(\"namespace %q using non-existent quota %q\", ns.Name, ns.Quota)\n\t\t}\n\t}\n\n\t// Insert the namespace\n\tif err := txn.Insert(TableNamespaces, ns); err != nil {\n\t\treturn fmt.Errorf(\"namespace insert failed: %v\", err)\n\t}\n\n\t// Reconcile changed quotas\n\treturn s.quotaReconcile(index, txn, ns.Quota, oldQuota)\n}\n\n// DeleteNamespaces is used to remove a set of namespaces\nfunc (s *StateStore) DeleteNamespaces(index uint64, names []string) error {\n\ttxn := s.db.WriteTxn(index)\n\tdefer txn.Abort()\n\n\tfor _, name := range names {","sourceCodeStart":7080,"sourceCodeEnd":7116,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L7080-L7116","documentation":"When upserting a namespace that references a Quota, the state store validates the quota spec exists. This error means the namespace's Quota field names a quota that has never been created (or was deleted), so the namespace write is rejected.","triggerScenarios":"`nomad namespace apply -quota=<name>` or Namespace.Upsert API where the quota spec does not exist in the state store (quotaSpecExists returns false).","commonSituations":"Typo in the quota name; quota deleted before the namespace referencing it is updated; namespace config applied to a region/cluster where the quota was never created; infrastructure-as-code ordering issue (namespace applied before quota).","solutions":["Create the quota first: `nomad quota create <spec>` or apply the quota spec before the namespace","Fix the namespace's quota name to match an existing quota spec","If the quota should not apply, re-apply the namespace with -quota=\"\" (empty)","Reorder your IaC/apply steps so quota creation precedes namespace upsert"],"exampleFix":"// before\nnomad namespace apply -quota=team-a-quota team-a  // quota missing\n// after\nnomad quota create quota-spec.hcl\nnomad namespace apply -quota=team-a-quota team-a","handlingStrategy":"validation","validationCode":"q, _, err := client.Quotas().Info(ns.Quota, nil)\nif err != nil || q == nil {\n    return fmt.Errorf(\"quota %q must exist before namespace %q is applied\", ns.Quota, ns.Name)\n}","typeGuard":"func quotaExists(name string) bool { _, _, err := client.Quotas().Info(name, nil); return err == nil }","tryCatchPattern":"_, _, err := client.Namespaces().Register(ns, nil)\nif err != nil && strings.Contains(err.Error(), \"non-existent quota\") {\n    return fmt.Errorf(\"create the quota spec first or clear -quota on the namespace: %w\", err)\n}","preventionTips":["Apply quota specs before namespaces in IaC ordering","Lint namespace definitions against the live quota list before apply","Use empty Quota field when no quota is intended"],"tags":["nomad","namespace","quota","validation"],"backgroundTag":"referenced-resource-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}