hashicorp/nomad · error

no lifecycle hook provided

Error message

no lifecycle hook provided

What it means

TaskLifecycleConfig.Validate() requires the `hook` field to be one of prestart, poststart, or poststop. An empty `hook` value yields this error. It indicates the lifecycle block was provided but the hook name was omitted.

Source

Thrown at nomad/structs/structs.go:6187

	if d == nil {
		return nil
	}
	nd := new(TaskLifecycleConfig)
	*nd = *d
	return nd
}

func (d *TaskLifecycleConfig) Validate() error {
	if d == nil {
		return nil
	}

	switch d.Hook {
	case TaskLifecycleHookPrestart:
	case TaskLifecycleHookPoststart:
	case TaskLifecycleHookPoststop:
	case "":
		return fmt.Errorf("no lifecycle hook provided")
	default:
		return fmt.Errorf("invalid hook: %v", d.Hook)
	}

	return nil
}

var (
	// These default restart policies needs to be in sync with
	// Canonicalize in api/tasks.go

	DefaultServiceJobRestartPolicy = RestartPolicy{
		Delay:           15 * time.Second,
		Attempts:        2,
		Interval:        30 * time.Minute,
		Mode:            RestartPolicyModeFail,
		RenderTemplates: false,
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Set `hook` to one of `prestart`, `poststart`, or `poststop` in the task's lifecycle block.
  2. If the task is not meant to be a lifecycle task, remove the lifecycle block entirely.
  3. Fix the template/variable source producing an empty hook value.

Example fix

// before
lifecycle {
  hook = ""
}
// after
lifecycle {
  hook = "prestart"
}
Defensive patterns

Strategy: validation

Validate before calling

validHooks := map[string]bool{"prestart": true, "poststart": true, "poststop": true}
if lifecycle != nil && !validHooks[lifecycle.Hook] {
	return fmt.Errorf("lifecycle.hook must be one of prestart, poststart, poststop")
}

Prevention

When it happens

Trigger: Submitting a job with a `lifecycle { }` block attached to a task where `hook = ""` or the key is omitted/empty in HCL/JSON.

Common situations: Templated job files where the hook value is interpolated to an empty string; forgetting the `hook` key entirely; YAML/JSON job specs generated by tooling that writes an empty field.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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