File size: 1,277 Bytes
1f3a244
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "ai-0011", "name": "Terraform Resource Graph"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}}
{"type": "message", "message": {"role": "user", "content": "How does Terraform's resource graph work?"}}
{"type": "message", "message": {"role": "assistant", "content": "Terraform builds a Directed Acyclic Graph (DAG) of all resources, modules, and providers.\n\nGraph building pipeline (Plan):\n1. ConfigTransformer: create nodes from HCL config\n2. ReferenceTransformer: add dependency edges from variable references\n3. DestroyEdgeTransformer: ordering for destroy operations\n4. TransitiveReductionOptimizer: remove redundant edges\n\nDAG library (internal/dag):\n- Graph: vertices, edgesFrom, edgesTo maps\n- AcyclicGraph: adds topological sort, Tarjan's SCC for cycle detection\n- Walker: parallel execution with V*2 goroutines per vertex\n\nNode types:\n- NodeAbstractResource: base with config, schema, provider\n- NodeApplyableResourceInstance: apply-time execution\n- NodePlanDestroyableResourceInstance: destroy planning\n\nEach transformer is a GraphTransformer implementing Transform(*Graph) error.\n22+ transformers run in sequence to build the final graph."}}