用途:为 homelab 基础设施编写 OpenTofu 模块及其测试。模块放在 infrastructure/modules/,测试放在 infrastructure/modules/<name>/tests/。OpenTofu 版本固定在 .opentofu-version。
主要能力:每个模块需包含 variables.tf(带描述与校验的输入定义)、main.tf(主要资源与 locals)、outputs.tf(输出定义)、versions.tf(provider 与 OpenTofu 版本约束)以及 tests/ 目录下的 *.tftest.hcl 测试文件。测试文件用顶层 variables 块为所有 run 块设置默认值,run 块中只覆盖有差异的变量。
使用方式:运行测试用 task tg:test-<module>(例如 task tg:test-config),格式化用 task tg:fmt。测试始终使用 command = plan,只校验配置而不创建真实资源;断言针对模块输出而非内部资源。可用 expect_failures 验证变量校验规则。建议按关注点组织测试文件:plan.tftest.hcl(基本结构与输出)、validation.tftest.hcl(输入校验)、feature_<name>.tftest.hcl(功能开关行为)、edge_cases.tftest.hcl(边界条件)。测试功能开关时需同时覆盖启用与禁用两种状态。
适用场景:homelab 基础设施模块的开发与测试。
限制:资料未提供更多关于运行环境、依赖安装或收费的信息。