用途:在 homelab 环境中用 Terragrunt 与 OpenTofu 管理裸金属 Kubernetes 基础设施,从 PXE 启动到集群运行。架构说明见 infrastructure/CLAUDE.md,单元模式见 infrastructure/units/CLAUDE.md。
主要能力:通过 task 命令完成格式化、模块测试、栈校验、列出栈、计划、应用、生成与清理。常用命令:task tg:fmt、task tg:test-<module>、task tg:validate-<stack>、task tg:list、task tg:plan-<stack>、task tg:apply-<stack>、task tg:gen-<stack>、task tg:clean-<stack>。禁止直接运行 terragrunt 或 tofu,必须使用 task 命令。
使用方式:添加机器时编辑 inventory.hcl,运行 task tg:plan-live,检查计划后需人工批准再应用;配置模块会自动纳入 cluster == "live" 的机器。添加特性开关需在 versions.hcl 加版本、在 modules/config/main.tf 做特性检测、在栈的 features 列表启用。创建新单元需建 units/new-unit/terragrunt.hcl 与 modules/new-unit/,并加入所需栈。
限制与注意:不得猜测 MAC 地址或 IP,须核对 inventory.hcl;不得提交 .terragrunt-cache/ 或 .terragrunt-stack/;不得手动编辑 Terraform 状态。删除带索引资源的状态条目时,xargs 会破坏引号,应改用 while 循环:terragrunt state list | while read -r resource; do terragrunt state rm "$resource"; done。校验顺序为 task tg:fmt、task tg:test、对所有栈执行 task tg:validate-<stack>、审查 task tg:plan-<stack>。