Skip to content

Circular Dependencies Guide

This guide explains the current circular-dependency story in netherframe.

What Counts As A Circular Dependency

A circular dependency exists when resources depend on each other in a cycle. Typical examples include:

  • two security groups that reference each other
  • cross-stack resources whose references form a cycle
  • multi-resource chains that loop back to an earlier node

Enable Circular Dependency Resolution

from nf.core import App

app = App(nf_id="app", enable_circular_dep_resolution=True)

It is also a setting: nf --circular-dep-resolution or enable_circular_dep_resolution in [tool.nf.config] (see the settings reference).

Current Resolution Model

netherframe resolves supported cycles through phased execution:

  1. the first phase creates every resource, leaving out the references that close each cycle, and records the values of the resources they refer to in the stack's state
  2. the last phase sets those references from the recorded values, so no phase has a cycle Terraform rejects
  3. stacks that read each other's outputs in a cycle are applied a phase at a time, in the order the export manifest gives

The phase planner decides how many phases are needed. A reference in a required argument is never left out; see Circular Dependency Resolution for how cycles are broken and what the export contains.

Supported Scope

Supported:

  • intra-stack cycles
  • cross-stack cycles inside the same App
  • multi-phase cycle resolution where more than two phases are required

Not supported:

  • circular references across different App instances
  • cycles whose every reference is in a required argument (or count, for_each, lifecycle, provider), or refers to an ephemeral resource: synthesis fails naming the cycle
  • cycles within a stack that keeps its state in a state_store, whose phases cannot record values

Standard Workflow

In the default Terraform-oriented path:

nf synth
nf deploy

When cycles are present, netherframe synthesizes phased artifacts for the affected stack output instead of a single flat plan.

Hybrid Workflow

Hybrid execution can also operate with circular-dependency support enabled:

from nf.core import App


def deploy() -> None:
    app = App(nf_id="app", enable_circular_dep_resolution=True)
    # ... stacks and resources ...
    hybrid = app.enable_hybrid_execution()
    result = hybrid.apply(auto_approve=True)
    print(result.complete)

Best Practices

  • enable circular dependency resolution at the app level when you know the graph requires it
  • prefer proper resource references over stringly assembled identifiers
  • inspect synthesized phase output when debugging a complex cycle
  • if a design keeps producing many phases, reconsider the architecture rather than only tuning the planner