Open source

Referencing component exports

Referencing exports is what enables River to dynamically configure and connect components using expressions. While components can work in isolation, they’re more useful when one component’s behavior and data flow is bound to the exports of another, building a dependency relationship between the two.

Such references can only appear as part of another component’s arguments or a config block’s fields. That means that components cannot reference themselves.

Using references

These references are built by combining the component’s name, label and named export with dots.

For example, the contents of a file exported by the local.file component labeled target might be referenced as Similarly, a prometheus.remote_write component instance labeled onprem will expose its receiver for metrics on prometheus.remote_write.onprem.receiver.

Let’s see that in action:

local.file "target" {
  filename = "/etc/agent/target"

prometheus.scrape "default" {
  targets    = [{ "__address__" = }]
  forward_to = [prometheus.remote_write.onprem.receiver]

prometheus.remote_write "onprem" {
  endpoint {
    url = "http://prometheus:9009/api/prom/push"

In the previous example, we managed to wire together a very simple pipeline by writing a few River expressions.

Flow of example pipeline

As with all expressions, once the value is resolved, it must match the type of the attribute being assigned to. While users can only configure attributes using the basic River types, the exports of components can also take on special internal River types such as Secrets or Capsules, which expose different functionality.