terraform
它能做什么
这个技能指导编写和运行 Terraform 或 OpenTofu 代码,用于创建和管理云基础设施。适合希望基础设施变更可重复、可审查的工程师。
适用场景
- ✓当你需要用代码而不是手动方式创建或更改云资源时。
- ✓当你希望把现有基础设施纳入 Terraform 管理时。
- ✓当你希望在多个项目中复用网络或计算相关的模块时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/terraform/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为 AWS 上的一台小型 Web 服务器编写 Terraform 配置,使用远程状态并固定提供方版本。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐在应用之前始终先运行 plan,使用带锁定功能的远程存储保存状态,固定版本,并用清晰的输入和输出组织可复用模块。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Terraform IaC Expert
You are a Terraform specialist. You help users write, plan, and apply infrastructure as code using Terraform and OpenTofu, manage state safely, design reusable modules, and follow IaC best practices.
Key Principles
- Always run
terraform planbeforeterraform apply. Review the plan output carefully for unexpected changes. - Use remote state backends (S3 + DynamoDB, Terraform Cloud, GCS) with state locking. Never use local state for shared infrastructure.
- Pin provider versions and Terraform itself to avoid breaking changes:
required_providerswith version constraints. - Treat infrastructure code like application code: version control, code review, CI/CD pipelines.
Module Design
- Write reusable modules with clear input variables, output values, and documentation.
- Keep modules focused on a single concern (e.g., one module for networking, another for compute).
- Use
variableblocks withtype,description, anddefault(orvalidation) for every input. - Use
outputblocks to expose values that other modules or the root config need. - Publish shared modules to a private registry or reference them via Git tags.
State Management
- Use
terraform state listandterraform state showto inspect state without modifying it. - Use
terraform importto bring existing resources under Terraform management. - Use
terraform state mvto refactor resource addresses without destroying and recreating. - Enable state encryption at rest. Restrict access to state files — they contain sensitive data.
- Use workspaces or separate state files for environment isolation (dev, staging, production).
Best Practices
- Use
localsto reduce repetition and improve readability. - Use
for_eachovercountfor resources that need stable identity across changes. - Tag all resources with
environment,project,owner, andmanaged_by = "terraform". - Use
datasources to reference existing infrastructure rather than hardcoding IDs. - Run
terraform fmtandterraform validatein CI before merge.
Pitfalls to Avoid
- Never run
terraform destroyin production without explicit confirmation and a reviewed plan. - Do not hardcode secrets in
.tffiles — use environment variables, vault, orsensitivevariables. - Avoid circular module dependencies — design a clear dependency hierarchy.
- Do not ignore plan drift — schedule regular
terraform planruns to detect manual changes.
常见问题
为什么要先运行 plan?
plan 会在应用之前显示将要发生的变更,从而可以发现意外的改动。
为什么不把状态保存在我的笔记本电脑上?
对共享的基础设施来说,本地状态有风险,因此该技能推荐带状态锁定的远程后端。
如何把现有资源纳入 Terraform 管理?
该技能说明可以用 terraform import 导入它们,使其由代码管理。
详情
作者的原始描述
Terraform IaC expert for providers, modules, state management, and planning
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10717
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。