Component exports
You learned about expressions and how the component controller evaluates them in the previous topics. Now you’ll learn how to use component references. These are expressions that connect components by referencing their exports.
Component references create the connections that make Alloy pipelines work. When you reference one component’s exports in another component’s arguments, you establish a dependency relationship that the component controller manages automatically.
References can only appear in component arguments or configuration block fields. Components can’t reference themselves.
Use references
You create references by combining the component’s name, label, and named export with dots.
For example, you can refer to the contents of a file exported by the local.file component labeled target as local.file.target.content.
Similarly, a prometheus.remote_write component instance labeled onprem exposes its receiver for metrics as prometheus.remote_write.onprem.receiver.
The following example demonstrates references:
local.file "target" {
filename = "/etc/alloy/target"
}
prometheus.scrape "default" {
targets = [{ "__address__" = local.file.target.content }]
forward_to = [prometheus.remote_write.onprem.receiver]
}
prometheus.remote_write "onprem" {
endpoint {
url = "http://prometheus:9009/api/prom/push"
}
}In the preceding example, you created a pipeline by writing a few Alloy expressions:
- The
local.filecomponent reads a file and exports itscontent. - The
prometheus.scrapecomponent references that content in itstargetsfield. - The
prometheus.scrapecomponent exports areceiverfor scraped metrics. - The
prometheus.remote_writecomponent receives and forwards those metrics to a remote endpoint.
When the component controller evaluates these components, it:
- Evaluates the
local.filecomponent first because it has no dependencies. - Evaluates the
prometheus.scrapecomponent next, using the file content for its targets. - Evaluates the
prometheus.remote_writecomponent last, connecting it to receive metrics.
Each time the file content changes, the component controller automatically reevaluates the prometheus.scrape component with the new target value.

The component controller evaluates component references during the component evaluation process. When you reference another component’s export, the component controller ensures that:
- The referenced component is evaluated first.
- The reference resolves to the correct export value.
- The resolved value’s type is compatible with the target field.
After a reference resolves, the value must match the type of the attribute it’s assigned to. While you can only configure attributes using the basic Alloy types, component exports can use special internal Alloy types, such as Secrets or Capsules, which provide additional functionality.
Next steps
Now that you understand component references, continue learning about expressions:
- Types and values - Learn how the type system ensures references work correctly with different data types
- Function calls - Use built-in functions to transform values from referenced exports
- Operators - Combine referenced values with other expressions using mathematical and logical operators



