hashicorp/nomad · error

Service address_mode must be %q, %q, or %q; not %q

Error message

Service address_mode must be %q, %q, or %q; not %q

What it means

In Service.Validate's AddressMode switch, the configured AddressMode fell into the default case, i.e. it was not one of the supported values (auto, host, driver, alloc, alloc_ipv6) — typically a typo in the jobspec address_mode field.

Source

Thrown at nomad/structs/services.go:781

	// Ensure the service name is valid per the below RFCs but make an exception
	// for our interpolation syntax by first stripping any environment variables from the name

	serviceNameStripped := args.ReplaceEnvWithPlaceHolder(s.Name, "ENV-VAR")

	if err := s.ValidateName(serviceNameStripped); err != nil {
		// Log actual service name, not the stripped version.
		mErr.Errors = append(mErr.Errors, fmt.Errorf("%v: %q", err, s.Name))
	}

	switch s.AddressMode {
	case "", AddressModeAuto:
	case AddressModeHost, AddressModeDriver, AddressModeAlloc, AddressModeAllocIPv6:
		if s.Address != "" {
			mErr.Errors = append(mErr.Errors, fmt.Errorf("Service address_mode must be %q if address is set", AddressModeAuto))
		}
	default:
		mErr.Errors = append(mErr.Errors, fmt.Errorf("Service address_mode must be %q, %q, or %q; not %q", AddressModeAuto, AddressModeHost, AddressModeDriver, s.AddressMode))
	}

	switch s.OnUpdate {
	case "", OnUpdateIgnore, OnUpdateRequireHealthy, OnUpdateIgnoreWarn:
		// OK
	default:
		mErr.Errors = append(mErr.Errors, fmt.Errorf("Service on_update must be %q, %q, or %q; not %q", OnUpdateRequireHealthy, OnUpdateIgnoreWarn, OnUpdateIgnore, s.OnUpdate))
	}

	// Up until this point, all service validation has been independent of the
	// provider. From this point on, we have different validation paths. We can
	// also catch an incorrect provider parameter.
	switch s.Provider {
	case ServiceProviderConsul:
		s.validateConsulService(&mErr)
	case ServiceProviderNomad:
		s.validateNomadService(&mErr)
	default:

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use one of: auto, host, driver, alloc, alloc_ipv6
  2. Omit address_mode entirely to use the default auto
  3. Fix the typo in the mode string

Example fix

// before
address_mode = "hosts"
// after
address_mode = "host"
Defensive patterns

Strategy: validation

Validate before calling

var modes = []string{"","auto","host","driver","alloc","alloc-ipv6"}
if !slices.Contains(modes, s.AddressMode) {
    return fmt.Errorf("invalid address_mode %q", s.AddressMode)
}

Prevention

When it happens

Trigger: Setting address_mode to an unrecognized value (typo like "hosts", "bridge", or old removed modes) on a service and validating it.

Common situations: Upgrading from old Nomad versions where different modes existed; typos; copying configs between Nomad and Consul template syntax.

Related errors


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