hashicorp/nomad · error

Service %s is Connect Native and requires setting the task

Error message

Service %s is Connect Native and requires setting the task

What it means

When a service is Connect Native (connect { sidecar_service {} } with native via service registration flags — Connect.IsNative()), Nomad requires the `task` field on the service so the service can be attributed to and run within a specific task's namespace. If the task name is empty, validation fails. Normally job mutation fills this implicitly when there is only one task, so this error mostly appears in multi-task groups.

Source

Thrown at nomad/structs/services.go:895

	case api.ServiceKindTypical,
		api.ServiceKindAPIGateway,
		api.ServiceKindIngressGateway,
		api.ServiceKindMeshGateway,
		api.ServiceKindTerminatingGateway:
	default:
		mErr.Errors = append(mErr.Errors, fmt.Errorf("Service %s kind must be one of consul service kind or empty", s.Name))
	}

	// check connect
	if s.Connect != nil {
		if err := s.Connect.Validate(); err != nil {
			mErr.Errors = append(mErr.Errors, err)
		}

		// if service is connect native, service task must be set (which may
		// happen implicitly in a job mutation if there is only one task)
		if s.Connect.IsNative() && len(s.TaskName) == 0 {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Service %s is Connect Native and requires setting the task", s.Name))
		}

		// if service is connect native a port must be set on the service or consul will reject it
		if s.Connect.IsNative() && s.PortLabel == "" {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Service %s is Connect Native and requires setting the port", s.Name))
		}
	}
}

// validateNomadService performs validation on a service which is using the
// nomad provider.
func (s *Service) validateNomadService(mErr *multierror.Error) {
	// check checks
	for _, c := range s.Checks {
		// validate the check port
		if err := s.validateCheckPort(c); err != nil {
			mErr.Errors = append(mErr.Errors, err)
			continue

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Add `task = "<task-name>"` to the service stanza naming the task that is Connect Native.
  2. Ensure the connect stanza is marked native (and the task binary actually supports Connect Native).
  3. If the service is not meant to be native, remove the native configuration so the sidecar path is used.

Example fix

// before
service {
  name = "native-svc"
  connect { sidecar_service {} }
}
// after
service {
  name = "native-svc"
  task = "app"
  connect { sidecar_service {} }
}
Defensive patterns

Strategy: validation

Validate before calling

if svc.Connect != nil && svc.Connect.IsNative() && svc.TaskName == "" {
  return fmt.Errorf("connect-native service %q must set task", svc.Name)
}

Prevention

When it happens

Trigger: A Connect Native service (Connect.IsNative() true) in a task group with multiple tasks where `task` is not set on the service stanza.

Common situations: Multi-task allocations with a Connect Native service; manually written jobs omitting the task field; jobs copied from single-task examples into multi-task groups.

Related errors


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