Terraform
$ terraform 官方出品 高风险HashiCorp Terraform(terraform)通过声明式 HCL 配置编排多云基础设施,具备典范级自动化能力:支持 -json 机器输出、-input=false 禁用输入等待、-no-color 去除色彩,以及先 plan 后 terraform show -json / validate -json 审查的严谨变更工作流。
brew install hashicorp/tap/terraform terraform 直接在本地仓库针对 HCL 与状态文件执行 validate -json、plan -out 与 show -json,大模型掌握极深,无需 MCP 中转。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
validate、plan、apply、show 与 output 全面支持 -json,且配备 -input=false 与 -no-color。
- Supports
-json,-input=false,-no-color, andshow -json
plan -out + show -json + apply <plan> 两阶段工作流可严防意外重建,但状态文件可能包含明文敏感字段。
- Saved plan artifacts guarantee apply matches reviewed diff
单文件静态 Go 二进制跨平台易装,但 terraform init 需联网下载对应 Provider 插件。
- Single Go binary via
brew install hashicorp/tap/terraform
多云基础设施即代码的事实标准,大模型预训练熟悉度极高。
- Universal multi-cloud provider ecosystem
HashiCorp 官方(hashicorp/terraform)持续维护,但 2023 年转为 BSL-1.1 协议后衍生了 OpenTofu 分支。
- Official
hashicorp/terraformunder BSL-1.1
具备极其详尽的 HashiCorp 官方 CLI 与 Provider 文档。
- Complete docs at developer.hashicorp.com/terraform
安全边界、鉴权与放权指南
将 Registry 令牌保存在 ~/.terraform.d/credentials.tfrc.json 或 TF_TOKEN_*,云厂商凭证则读取 AWS_*、GOOGLE_*、ARM_* 等环境变量。
CLI 本身按 BSL-1.1 免费提供(HCP Terraform 云服务分级收费);编排创建的云资源会产生对应厂商费用。
# Terraform Agent Rules - ALWAYS pass `-input=false -no-color` (and `-json` where supported) to prevent hangs. - Run `terraform validate -json` and `terraform plan -out=tfplan.bin` first; inspect `terraform show -json tfplan.bin` for `delete`/replacement actions. - NEVER run `terraform apply -auto-approve` or `terraform destroy` without explicit human review.
Agent 高频安全命令配方
只读查询(安全推荐)
terraform validate -json -no-color
在本地验证配置合法性并输出结构化诊断 JSON。
terraform plan -input=false -no-color -out=tfplan.bin && terraform show -json tfplan.bin
非交互生成不可变计划文件,并打印全部资源增删改明细 JSON。
受控写入与预演
terraform apply -input=false -no-color -json tfplan.bin
严格按 tfplan.bin 执行变更并输出流式 JSON 事件,杜绝计划外漂移。
核心优势
- +
plan -out搭配show -json与apply <plan>构成了业界标杆级的变更审查链路。 - +
-input=false与-no-color确保自动化环境永不阻塞。 - + 拥有最广泛的云生态 Provider 与最高的大模型语法准确率。
注意事项与踩坑点
- ! BSL-1.1 许可证限制将其嵌入竞争性 SaaS/IaC 商业产品。
- !
terraform show -json与状态文件(terraform.tfstate)中可能包含明文敏感资源属性。