Trace a component reference
References are how components connect, so reading one is a core skill. The following example shows how one component’s export supplies another component’s argument. You don’t need to run it.
local.file "example" {
filename = sys.env("HOME") + "/file.txt"
}
prometheus.remote_write "local_prom" {
endpoint {
url = "http://localhost:9090/api/v1/write"
basic_auth {
username = "admin"
password = local.file.example.content
}
}
}This example has two components. You already met local.file, which reads a file and exports its contents. prometheus.remote_write sends metrics to a Prometheus-compatible endpoint. Inside it, endpoint and basic_auth are nested argument blocks that group related settings.
Read the source component
Start with the local.file "example" block. You already know the name and label. What’s new here is the filename expression: sys.env("HOME") + "/file.txt" builds the path at runtime.
As before, this component type also provides a content export. That export isn’t written in the block. Other components reference it.
Find and read the reference
Now find where that export is used. The password argument inside basic_auth is set to local.file.example.content. Read that expression from left to right:
local.fileidentifies the component type.exampleidentifies the labeled instance.contentidentifies the export.
The component type and label together, local.file.example, are the component’s fully qualified name.
The reference means Alloy evaluates local.file.example first, then supplies its content export as the password argument. This single reference creates a dependency: prometheus.remote_write.local_prom depends on local.file.example.