SuperAPI AI 工具集

infrastructure-terraform

部署与运维

查看项目

更新于 10-15 23:49

技能介绍

用途:在本地编写或修改 Terraform HCL 配置、针对后端运行 init/plan/apply/destroy、设计模块结构、provider 与远程后端,以及排查本地状态、漂移与导入工作流时,调用本技能获取专家知识。涉及 Terraform Cloud 运行状态、计划 JSON 或运行历史时,应改用 tfc-* 系列技能(如 tfc-run-status、tfc-run-logs、tfc-plan-json、tfc-list-runs 等)。

主要能力:声明式与模块化 HCL;使用远程后端保护和管理 state;使用社区与自定义 provider/模块;掌握 plan→review→apply 执行生命周期;变量与 output 参数化;状态调试与恢复。

必要用法:核心工作流为 terraform init、terraform plan、terraform apply、terraform destroy。状态操作用 terraform state list、terraform state show <resource>、terraform state pull > backup.tfstate。校验与格式化用 terraform validate、terraform fmt -recursive、terraform fmt path/to/dir、terraform graph | dot -Tsvg > graph.svg。跨目录时用 -chdir,例如 terraform -chdir=gcp fmt、terraform -chdir=gcp validate、terraform -chdir=gcp plan、terraform -chdir=modules/vpc init。调试可用 export TF_LOG=DEBUG、terraform plan -out=tfplan、terraform show tfplan。导入与漂移处理用 terraform import、terraform refresh、terraform plan -refresh-only。常见 flag 包括 -chdir、-recursive、-check、-compact-warnings、-json、-out、-target、-refresh-only。

最佳实践:先 plan 并仔细审阅再变更;拆分为可复用模块;使用带锁定的远程后端保护 state;用变量和 output 提升可配置性;执行 destroy 前再次确认计划;provider 指定来源与版本约束、声明 required_version。

适用场景与限制:适用于本地 Terraform 配置编写、模块与后端设计、状态与漂移排查、CI 中的格式与校验检查。资料未提供安装命令、收费方式、平台范围及更详细的调试模式、高级模块设计、CI/CD 集成内容,需参见其 REFERENCE.md。