{"record":{"id":"36101835ee34babf","repo":"hashicorp/nomad","slug":"dynamic-user-max-must-be-set","errorCode":null,"errorMessage":"dynamic_user_max must be set","messagePattern":"dynamic_user_max must be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/config/users.go","lineNumber":67,"sourceCode":"func (u *UsersConfig) Equal(o *UsersConfig) bool {\n\tif u == nil || o == nil {\n\t\treturn u == o\n\t}\n\tswitch {\n\tcase !pointer.Eq(u.MinDynamicUser, o.MinDynamicUser):\n\t\treturn false\n\tcase !pointer.Eq(u.MaxDynamicUser, o.MaxDynamicUser):\n\t\treturn false\n\tdefault:\n\t\treturn true\n\t}\n}\n\nvar (\n\terrUsersUnset            = errors.New(\"users must not be nil\")\n\terrDynamicUserMinUnset   = errors.New(\"dynamic_user_min must be set\")\n\terrDynamicUserMinInvalid = errors.New(\"dynamic_user_min must not be negative\")\n\terrDynamicUserMaxUnset   = errors.New(\"dynamic_user_max must be set\")\n\terrDynamicUserMaxInvalid = errors.New(\"dynamic_user_max must not be negative\")\n)\n\n// Validate whether UsersConfig is valid.\n//\n// Note that -1 is a valid value for min/max dynamic users, as this is used\n// to indicate the dynamic workload users feature should be disabled.\nfunc (u *UsersConfig) Validate() error {\n\tif u == nil {\n\t\treturn errUsersUnset\n\t}\n\tif u.MinDynamicUser == nil {\n\t\treturn errDynamicUserMinUnset\n\t}\n\tif *u.MinDynamicUser < -1 {\n\t\treturn errDynamicUserMinInvalid\n\t}\n\tif u.MaxDynamicUser == nil {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/config/users.go#L49-L85","documentation":"errDynamicUserMaxUnset is returned by UsersConfig.Validate() when MaxDynamicUser is a nil pointer. Like the min bound, the maximum dynamic UID must be explicitly configured; a nil pointer means the field was never set and validation fails. -1 is allowed and disables the feature.","triggerScenarios":"UsersConfig built with only MinDynamicUser set (MaxDynamicUser nil) — e.g. an HCL users block with dynamic_user_min but no dynamic_user_max — passed through Validate().","commonSituations":"Partial users stanza in agent config; code constructing UsersConfig and forgetting the max bound; JSON decode of a config missing the key yielding nil.","solutions":["Add `dynamic_user_max` to the users config block (integer >= -1; -1 disables the feature).","Set MaxDynamicUser when constructing the struct programmatically.","Use errors.Is(err, errDynamicUserMaxUnset) in tests to assert this specific failure."],"exampleFix":"// HCL before\nusers {\n  dynamic_user_min = 1000\n}\n\n// HCL after\nusers {\n  dynamic_user_min = 1000\n  dynamic_user_max = 1500\n}","handlingStrategy":"validation","validationCode":"if u != nil && u.MaxDynamicUser == nil {\n    return fmt.Errorf(\"dynamic_user_max must be set (use -1 to disable)\")\n}","typeGuard":null,"tryCatchPattern":"if err := u.Validate(); err != nil {\n    if errors.Is(err, errDynamicUserMaxUnset) {\n        return fmt.Errorf(\"set dynamic_user_max in the users config block\")\n    }\n    return err\n}","preventionTips":["Always pair dynamic_user_min with dynamic_user_max in the users block.","Apply defaults in the config decoder so neither bound is nil.","Add table-driven tests (as in TestUsersConfig_Validate) covering the nil-max case."],"tags":["nomad","agent-config","validation"],"backgroundTag":"missing-required-argument","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"}