Skip to content

nf follow

Follow an apply or destroy that runs elsewhere (another terminal, a teammate's machine, CI) as nf apply shows its own run: each resource as it finishes, what is in flight and for how long, then a summary. Following only reads: Ctrl-C stops following, never the run. nf tui follow follows it in the terminal UI instead (see nf tui).

Synopsis

nf follow [OPTIONS]

How it Works

A hybrid apply or destroy keeps a small run status up to date where its state is kept: who runs it and where, its phase (planning, waiting for its approval, changing infrastructure, stopping, finished), the changes it planned, what is in flight, its last 256 events (each numbered, so a watcher that keeps up misses none) and, at the end, its outcome, errors and the changes it left deferred (by address). It holds addresses, actions and status only, never attribute values.

The status is one document, overwritten rather than appended to, so it stays the same size however long the run. The run writes it from a background thread when something changed (at most every 2 seconds) and every 10 seconds otherwise: that heartbeat is how a watcher tells a live run from one that died holding its lock.

State backend Where the status is What a watcher sees
Local <state>.run.json beside the state file everything above
S3, GCS, Azure Blob, Consul <state key>.run.json beside the state object (encrypted as the state is) everything above
Graph state (PostgreSQL) nothing extra: the run's operation and history rows each change as its operation commits, what is dispatched; no planned totals, no phase before changes start, an outcome inferred from aborted operations
HCP Terraform, PostgreSQL document state none the lock holder, until the lock is released

The status of the last run stays until the next run replaces it, so nf follow after a run ended still shows how it ended.

Writing the status never fails a run: a write that fails is logged once and tried again, and after repeated failures the run stops writing it. On S3, a policy that only allows the state key itself needs s3:PutObject/s3:GetObject on <state key>.run.json too (as checkpoints need <state key>.checkpoints/*). Turn the status off with --no-run-status on nf apply, nf destroy or nf deploy, run_status = false under [tool.nf.config], or App(run_status=False).

Finding the Run

Without --run, nf follow follows the app's run in progress. When none is, it shows how the last one ended and exits with its outcome; --wait waits for the next run to start instead. In CI, start the run first, or pass --wait, so following does not report the previous run.

On a graph state backend with concurrent applies, several runs can be in progress: --run ID follows one of them (the TUI's :runs lists their IDs).

nf follow builds the app to find its state, so an app whose inputs choose its state is followed with the same inputs: nf follow --app web ++env=prod follows production's run (see nf vars). The header names the inputs the run was built with.

Exit Codes

Code Meaning
0 the run succeeded (or, without a live status, its lock was released)
2 the run succeeded and left deferred changes (incomplete_exit_code, as for nf apply)
1 the run failed, was stopped or declined; or there is no run to follow
124 --timeout passed; the run goes on
130 Ctrl-C: following stopped; the run goes on

So nf follow --wait && ./smoke-tests.sh runs the tests once the next deployment succeeds.

Options

  • --app TEXT: the hybrid app whose run to follow (the only one when the project has one)
  • --run TEXT: follow this run by its ID
  • --interval FLOAT: seconds between reads of the status (default 2)
  • --wait: with no run in progress, wait for the next one to start
  • --timeout FLOAT: stop following after this many seconds (exit 124)
  • --notify: send a desktop notification when the run ends (notify-send, or osascript on macOS); the terminal bell rings either way
  • --outdir PATH: the app's output directory (where local state is)

Examples

# Follow the deployment a teammate just started
nf follow --app web

# In CI: wait for the next run, then fail the job if it fails
nf follow --app web --wait --timeout 3600

# Follow one of several concurrent graph-state runs
nf follow --app web --run 3f2a91c04d7e

Notes

  • A run that stops writing its heartbeat for 30 seconds is reported as possibly dead. Its state lock stays until it is released; check that the run is really gone before nf state force-unlock.
  • nf tui follows the same runs: they show in :runs (with who runs them), in a run view, on :graph and in the overview; nf tui follow opens on one. ctrl-k does not stop them: stop a run where it runs.
  • Legacy (--stack) runs are Terraform's and write no status.