{"record":{"id":"e10126b92f7349d3","repo":"hashicorp/nomad","slug":"port-label-q-referenced-by-services-v-does-not-e","errorCode":null,"errorMessage":"port label %q referenced by services %v does not exist","messagePattern":"port label %q referenced by services (.+?) does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":8615,"sourceCode":"\tfor p := range servicePorts {\n\t\tkeys = append(keys, p)\n\t}\n\tsort.Strings(keys)\n\n\t// Ensure all ports referenced in services exist.\n\tfor _, servicePort := range keys {\n\t\tservices := servicePorts[servicePort]\n\t\t_, ok := portLabels[servicePort]\n\t\tif !ok {\n\t\t\tnames := make([]string, 0, len(services))\n\t\t\tfor name := range services {\n\t\t\t\tnames = append(names, name)\n\t\t\t}\n\n\t\t\t// Keep order deterministic\n\t\t\tsort.Strings(names)\n\t\t\tjoined := strings.Join(names, \", \")\n\t\t\terr := fmt.Errorf(\"port label %q referenced by services %v does not exist\", servicePort, joined)\n\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t}\n\t}\n\n\t// Ensure address mode is valid\n\treturn mErr.ErrorOrNil()\n}\n\nfunc (t *Task) Warnings() error {\n\tvar mErr multierror.Error\n\n\t// Validate the resources\n\tif t.Resources != nil && t.Resources.IOPS != 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"IOPS has been deprecated as of Nomad 0.9.0. Please remove IOPS from resource block.\"))\n\t}\n\n\tif t.Resources != nil && len(t.Resources.Networks) != 0 {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"task network resources have been deprecated as of Nomad 0.12.0. Please configure networking via group network block.\"))","sourceCodeStart":8597,"sourceCodeEnd":8633,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L8597-L8633","documentation":"This validation error comes from Nomad's service block validation in Task/group validation. A service (or check) references a port label that is not defined in the task's or group's network resources (or port block) of the job spec. Nomad collects all offending services and reports them together as a multierror before returning validation failure.","triggerScenarios":"Submitting a job (jobs/validate or job register) whose `service { port = \"http\" }` (or a service check port label, or connect sidecar_service port) names a port label absent from the group/task `network { port ... }` blocks. Thrown from the validate path that collects service port labels, sorts them, and appends one error per missing port label.","commonSituations":"Renaming a port in the network block but not in the service block; copying a service stanza from another job with different port labels; using static vs dynamic port labels incorrectly; typos like \"http-port\" vs \"http\"; removing the network block entirely while services remain.","solutions":["Add a matching port block to the group network: network { port \"http\" {} } so the label exists.","Change the service's `port` field to reference an existing port label exactly.","If the service is for Consul Connect, use the connect stanza's implicit port or set `address_mode` correctly for the intended network.","Run `nomad job validate` (or hit the /v1/validate endpoint) before submit to catch the mismatch early."],"exampleFix":"// before\nservice {\n  name = \"web\"\n  port = \"http\"\n}\n// (no network port defined)\n\n// after\nnetwork {\n  port \"http\" {}\n}\nservice {\n  name = \"web\"\n  port = \"http\"\n}","handlingStrategy":"validation","validationCode":"// Pre-check: every service/check port label exists in the group network ports\nfunc checkServicePorts(group map[string][]string /* label -> services */, ports map[string]bool) error {\n  for label, svcs := range group {\n    if !ports[label] {\n      return fmt.Errorf(\"port label %q referenced by services %v does not exist\", label, svcs)\n    }\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define group-level network port blocks before adding services.","Keep a canonical map of port labels per job and reference only those in services/checks.","Run `nomad job validate` in CI for every job spec change."],"tags":["nomad","job-spec-validation","service","ports"],"backgroundTag":"missing-port-label","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"}