TFLint
$ tflint 社区开源 低风险tflint 超越了基础的 terraform validate,能够依据 AWS、Azure、GCP 等云厂商插件规则及 HCL 命名规范检查代码。它支持非交互运行、--recursive 多模块递归扫描,并通过 --format json 输出清晰的诊断结果。
brew install tflint 原生支持 --format json 的本地 HCL 静态检查器,直接调用 CLI 比经过 MCP 中转更高效。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --format json、--format sarif、--format compact、--no-color 与 --recursive,退出码规范。
- Native
--format jsonand--no-colorflags - Headless
--recursivedirectory traversal
默认纯只读静态分析;仅 tflint --init 缓存插件或显式传入 --fix 时才会写入本地文件。
- Zero cloud credentials required; read-only default mode
静态 Go 单二进制,支持 macOS、Linux 与 Windows 的 Homebrew、Chocolatey、Docker 与发行包。
- Single static Go binary with cross-platform packages
在执行 terraform plan 之前即可拦截无效实例类型、废弃语法与未使用声明。
- Pluggable AWS/Azure/GCP rulesets catch provider-level errors offline
社区广泛采用的项目(terraform-linters/tflint),以 MPL-2.0 协议活跃维护。
- Active
terraform-linters/tflintrepo under MPL-2.0
仓库内用户指南、规则目录与 .tflint.hcl 配置说明详尽。
- Detailed user guide and rule docs in repository
安全边界、鉴权与放权指南
核心检查无需凭证;执行 tflint --init 下载插件时可读取 GITHUB_TOKEN 以避免 GitHub 速率限制。
MPL-2.0 开源免费。
# TFLint Agent Rules - Always pass `--format json` or `--format compact --no-color`. - Run `tflint --init` once if `.tflint.hcl` declares external plugins. - Do not pass `--fix` without reviewing `git diff` afterward.
Agent 高频安全命令配方
只读查询(安全推荐)
tflint --recursive --format json
扫描当前目录及所有子模块,输出结构化的 JSON 问题与错误清单。
tflint --no-color --format compact
输出精简的 file:line:col: message 诊断行,节省上下文 Token。
受控写入与预演
tflint --init
将 .tflint.hcl 中声明的插件下载到本地 ~/.tflint.d/plugins 缓存。
核心优势
- + 提供干净的
--format json与--format compact输出并支持--no-color。 - + 无需云端
plan即可在本地捕获厂商级资源参数错误。 - + 支持
--recursive一键扫描大型 Monorepo。
注意事项与踩坑点
- ! 启用云厂商特定规则前需联网执行一次
tflint --init。 - ! 复杂的动态 HCL 表达式偶尔需要配合配置屏蔽误报。