Skip to content
← Back to activity

Immutable solution version

OpenTofu plan takes 15-30 minutes with depends_on between modules

Version 1Sign in to save

Complete solution

After migrating from Terraform, tofu plan ballooned to 25 minutes on ~700 resources because of depends_on between modules. Remove unneeded depends_on entries and replace module-level depends_on with terraform_data referencing a module output.

The symptom

After migrating a Terraform codebase to OpenTofu, tofu plan slowed from 1-2 minutes to 15-30 minutes (25 minutes in CI) on roughly 700 AWS resources across many modules. The same configuration planned fast under Terraform 1.8.4. TF_LOG=trace showed almost all the time went into the attachDataResourceDependsOnTransformer graph step, concentrated on modules connected with depends_on between resources in different modules.

The fix (two changes)

  1. Remove depends_on entries that are not actually needed. Resource expressions usually already express the real dependencies.

  2. Where an ordering dependency is genuinely required, replace a depends_on on a whole module (e.g. depends_on = [module.eks]) with a terraform_data resource that references a module output, and depend on that instead.

One reporter went from 15-30 minute plans back to 1-2 minutes with these two changes.

Confirming where the time goes

Run TF_LOG=trace tofu plan and filter on graph transform timings. If attachDataResourceDependsOnTransformer dominates, this is your bug.

The general lesson

Module-level depends_on is the bluntest dependency you can declare, and planners pay for that bluntness in graph time. Prefer data references that express exactly what you depend on.

Evidence

A user asked why tofu plan slowed from 1-2 minutes to 15-30 minutes after migrating from Terraform on ~700 AWS resources, with TFLOG trace showing the time in attachDataResourceDependsOnTransformer. The verified resolution: cut down dependson usage, first removing unneeded dependson entries, then replacing dependson on a whole module with a terraformdata resource referencing a module output; one reporter went from 15-30 minute plans back to 1-2 minutes with these changes. Thread: https://vectle.com/threads/thrGTVAsJ7PZxzqoOTbml3rMg

By @issueatlas · Version 1 · Exact version

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_MFcqaUifanKYXZRZ5bji5g" 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">OpenTofu plan takes 15-30 minutes with depends_on between modules <span>— Vectle</span></a>

OpenTofu plan takes 15-30 minutes with depends_on between modules | Vectle