{"record":{"id":"6bec3051e6abc0cb","repo":"hashicorp/nomad","slug":"check-q-invalid-cannot-use-address-mode-driver","errorCode":null,"errorMessage":"Check %q invalid: cannot use address_mode=\"driver\", only checks defined in a \"task\" service block can use this mode","messagePattern":"Check %q invalid: cannot use address_mode=\"driver\", only checks defined in a \"task\" service block can use this mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7545,"sourceCode":"\t\t// Track that we have seen this service provider\n\t\tproviderSet.Insert(service.Provider)\n\n\t\tif err := service.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Service[%d] %s validation failed: %s\", i, service.Name, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t\t// we break here to avoid the risk of crashing on null-pointer\n\t\t\t// access in a later step, accepting that we might miss out on\n\t\t\t// error messages to provide the user.\n\t\t\tcontinue\n\t\t}\n\t\tif service.AddressMode == AddressModeDriver {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"service %q cannot use address_mode=\\\"driver\\\", only services defined in a \\\"task\\\" block can use this mode\", service.Name))\n\t\t}\n\n\t\tfor _, check := range service.Checks {\n\t\t\tif check.TaskName != \"\" {\n\t\t\t\tif check.AddressMode == AddressModeDriver {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Check %q invalid: cannot use address_mode=\\\"driver\\\", only checks defined in a \\\"task\\\" service block can use this mode\", service.Name))\n\t\t\t\t}\n\t\t\t\tif !taskSet.Contains(check.TaskName) {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors,\n\t\t\t\t\t\tfmt.Errorf(\"Check %s invalid: refers to non-existent task %s\", check.Name, check.TaskName))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Produce an error of any services which are not unique enough in the group\n\t// i.e. have same <task, name, port>\n\tif idDuplicateSet.Size() > 0 {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\n\t\t\t\t\"Services are not unique: %s\",\n\t\t\t\tidDuplicateSet.StringFunc(\n\t\t\t\t\tfunc(u unique) string {\n\t\t\t\t\t\ts := u.task + \"->\" + u.name","sourceCodeStart":7527,"sourceCodeEnd":7563,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7527-L7563","documentation":"A check declared task_name (i.e. a task-level check) and also set address_mode=\"driver\"; driver address mode is only allowed for checks defined within a task's service block, so this combination in a group-level service's checks is rejected. (The message uses the service's name, not the check's.)","triggerScenarios":"A group-level service with a check that sets task = \"...\" and address_mode = \"driver\"; validation iterates service.Checks and flags check.AddressMode == AddressModeDriver when check.TaskName != \"\".","commonSituations":"Copy-pasting checks from task services to group services; enabling driver address mode for Consul checks defined at group level; refactoring services between scopes.","solutions":["Remove address_mode=\"driver\" from the check (use host/auto).","Move the service and check into the task block where driver mode is permitted.","Drop the task field from the check if group-level host addressing is intended."],"exampleFix":"// before\ncheck \"health\" { address_mode=\"driver\" task=\"web\" }\n// after\ncheck \"health\" { address_mode=\"host\" }","handlingStrategy":"validation","validationCode":"for _, c := range svc.Checks {\n  if c.TaskName != \"\" && c.AddressMode == \"driver\" {\n    return fmt.Errorf(\"check %q: driver address_mode only valid in task services\", c.Name)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never combine task= with address_mode=driver at group level","Keep driver-mode checks inside task blocks","Validate service scope during HCL linting"],"tags":["nomad","check","address-mode","consul","validation"],"backgroundTag":"invalid-address-mode","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"}