Dependencies and Data Sources
Table of Contents
Introduction: The Circular Dependency Nightmare
What Are Dependencies?
Simple Example
The Dependency Challenge
Dependency Types
Implicit Dependencies
Basic Implicit Dependency
Multiple Implicit Dependencies
Chained Dependencies
Module Output Dependencies
Explicit Dependencies
When Implicit Isn't Enough
The depends_on Meta-Argument
Basic Usage
Multiple Dependencies
Module Dependencies
depends_on with count/for_each
When to Use depends_on
Understanding Data Sources
Resource vs Data Source
Why Data Sources?
Data Source Benefits
Using Data Sources
Local File Data Source
Template File Data Source
External Data Source
HTTP Data Source
Data Source with Dependencies
Remote State Data Sources
Why Remote State Data Sources?
Remote State with S3 Backend
Remote State Best Practices
Dependency Graph
Visualizing Dependencies
Simple Graph Example
Complex Graph
Analyzing the Graph
Lifecycle Meta-Arguments and Dependencies
create_before_destroy
prevent_destroy
ignore_changes
replace_triggered_by
Module Dependencies
Implicit Module Dependencies
Explicit Module Dependencies
Module Output Dependencies
Common Dependency Patterns
Pattern 1: Sequential Creation
Pattern 2: Fan-Out
Pattern 3: Fan-In
Pattern 4: Diamond Dependency
Real-World Example: Multi-Tier Application with Dependencies
Project Structure
Database Module
Application Module
Monitoring Module
Root Module
Dependency Graph
Supporting Files
Deploy
Debugging Dependency Issues
Enable Debug Logging
Analyze Dependency Graph
List Resource Dependencies
Trace Execution Order
Circular Dependencies
Example of Circular Dependency
Breaking Circular Dependencies
Parallel Resource Creation
Default Parallelism
Adjust Parallelism
What Can Run in Parallel?
Best Practices
1. Prefer Implicit Dependencies
2. Use depends_on Sparingly
3. Document Dependencies
4. Avoid Circular Dependencies
5. Use Data Sources for External Resources
6. Visualize Dependencies
7. Test Dependency Order
What I Learned About Dependencies
1. Dependencies Are About Data Flow
2. Implicit > Explicit
3. Data Sources Break Dependency Chains
4. Circular Dependencies Mean Design Problems
5. The Graph Is Your Map
6. Modules Are Dependency Boundaries
Next Steps
Practice Exercises
Coming Up Next
Last updated