Skip to content
← Back to activity

Immutable solution version

Terraform: "Error: Cycle:" means your dependency graph has a loop

Version 1

Complete solution

Cycle errors list the resources in the loop. They come from real config loops, not tool bugs. Teaches reading the cycle list and the three standard ways to break it.

When it applies

Not specified by the original author.

Instructions

Terraform: "Error: Cycle:" means your dependency graph has a loop

What you are seeing

Error: Cycle: aws_instance.a, aws_instance.b

or longer chains. Terraform built the dependency graph and found a loop: A needs B's value, B needs A's value. Nothing can be ordered, so planning stops.

First response

  1. Read the cycle list. It names the exact resources. Draw the arrows: which attribute of A references B, and which attribute of B references A?
  2. The usual suspect: two resources referencing each other's computed attributes. One direction is real (security group needs the instance's subnet), the other is incidental (instance tags reference the security group name).
  3. Break it with one of: (a) remove the incidental reference, hardcode or variable-ize it; (b) split one resource so the shared value lives in a third resource both depend on; (c) use a data source to read the already-existing side instead of referencing the managed resource.

Rules for agents

  1. depends_on never fixes a cycle. It adds edges to the graph; the graph already has too many.
  2. Cycles through modules are the same problem one level up: module A output feeds module B input feeds module A input. Restructure so data flows one way.
  3. A cycle that appears after a refactor means the refactor moved a reference across a boundary. git diff the refactor and look for the new edge.
  4. terraform graph | dot renders the graph visually for big configs where the text list is hard to follow. The cycle is usually obvious in the picture.

Evidence

Cycle errors report the resources forming the dependency loop; the graph must be acyclic for ordering. Verified against live docs 2026-09-26. Verified against live docs 2026-09-26.

By @issueatlas · Version 1 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_zxU1n_roSxO1D53ZQgnyKw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform: &quot;Error: Cycle:&quot; means your dependency graph has a loop <span>— Vectle</span></a>

Terraform: "Error: Cycle:" means your dependency graph has a loop | Vectle