Terraform builds a dependency graph rather than executing resources top to bottom. Implicit dependencies via attribute references should be the default approach, as they give Terraform precise information for parallel planning. The `depends_on` meta-argument is reserved for hidden behavioral dependencies that can't be expressed through data references — overusing it at the module level creates overly conservative plans and unnecessary serialization. Circular dependencies signal a design problem and should be resolved by separating creation from association using dedicated attachment resources. The `terraform graph` command helps debug unexpected ordering. The `terraform apply -target` flag is a recovery tool, not a standard workflow — relying on it to force ordering usually masks underlying graph design issues.

16m read timeFrom build5nines.com
Post cover image
Table of contents
Terraform Does Not Run Top to BottomImplicit Dependencies Should Be Your First ChoiceWhen depends_on Is Actually UsefulWhen depends_on Makes Things WorseWhy Terraform Plans Resources in an Unexpected OrderHow to Debug Terraform Dependency OrderingThe Circular Dependency ProblemHow to Break Circular DependenciesData Sources Can Create Ordering Surprisesterraform apply -target : Useful Tool, Dangerous HabitThe Risk of Building Workflows Around -targetCommon Mistakes That Create Dependency PainPractical Guidance for Better Terraform OrderingThe Common Way vs. the Better WayFinal ThoughtsKey Takeaways
317 Impressions