Section 4 · Reading Alloy configuration

Why component references can't form a loop

Estimated time: 1 min

Circular dependencies

In the previous slide, a reference created a dependency: prometheus.remote_write.local_prom depended on local.file.example. Alloy uses dependencies like that to decide which components to evaluate first. Because it needs a clear order, those dependencies can’t form a circle.

Invalid examples

A component can’t reference itself:

Alloy
// Invalid: direct self-reference.
local.file "self_reference" {
  filename = local.file.self_reference.content
}

Components also can’t reference each other in a loop:

Alloy
// Invalid: circular dependency.
local.file "a" {
  filename = local.file.b.content
}

local.file "b" {
  filename = local.file.a.content
}

Here, a depends on b, while b depends on a. Neither can be evaluated first.

How to spot a loop

When you read component references, follow each dependency in its direction. If following the references brings you back to a component you already visited, the configuration has a circular dependency and is invalid.