How 0xdones/tfgen works
Main Components
a. Input Layer:
• Configuration Files (.tfgen.yaml)
• Command Line Interface
b. Core Processing Components:
• Config Parser/Merger
• Template Engine
• File System Handler
c. Output Layer:
• Generated Terraform Files
Component Relationships and Flow
Use the following structure to show the data flow:
[CLI Commands] -----> [File System Scanner]
• v
[Config Files] -----> [Config Parser/Merger]
• v
[Templates] ---------> [Template Engine]
• v
[File System Handler] ---> [Generated Files]
Important Details
a. Configuration Flow:
• How multiple .tfgen.yaml files are merged (root and environment-specific)
• Precedence (inner config over outer config)
b. Template Processing:
• Injection of built-in variables (tfgen_state_key)
• Template variable substitution
c. File Generation:
• Output of standard files (_backend.tf, _provider.tf, _vars.tf)
Key Architectural Elements
• cmd/ - Command handling (clean.go, exec.go)
• tfgen/ - Core logic (config.go, finder.go, fs.go, handler.go)
• Main orchestration (main.go)
Additional Notes
• File naming conventions
• Configuration hierarchy
• Variable precedence
• Template syntax
Implementation Details
How the following key files interact:
• finder.go: Configuration file discovery
• config.go: Configuration parsing and merging
• handler.go: Template processing
• fs.go: File system operations