跳到正文
Skillpedia
部署与云(DevOps)18k · #10717

terraform

它能做什么

这个技能指导编写和运行 Terraform 或 OpenTofu 代码,用于创建和管理云基础设施。适合希望基础设施变更可重复、可审查的工程师。

适用场景

  • ✓当你需要用代码而不是手动方式创建或更改云资源时。
  • ✓当你希望把现有基础设施纳入 Terraform 管理时。
  • ✓当你希望在多个项目中复用网络或计算相关的模块时。

技能链接

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/terraform/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/terraform/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 plan before terraform 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_providers with 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 variable blocks with type, description, and default (or validation) for every input.
  • Use output blocks 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 list and terraform state show to inspect state without modifying it.
  • Use terraform import to bring existing resources under Terraform management.
  • Use terraform state mv to 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 locals to reduce repetition and improve readability.
  • Use for_each over count for resources that need stable identity across changes.
  • Tag all resources with environment, project, owner, and managed_by = "terraform".
  • Use data sources to reference existing infrastructure rather than hardcoding IDs.
  • Run terraform fmt and terraform validate in CI before merge.

Pitfalls to Avoid

  • Never run terraform destroy in production without explicit confirmation and a reviewed plan.
  • Do not hardcode secrets in .tf files — use environment variables, vault, or sensitive variables.
  • Avoid circular module dependencies — design a clear dependency hierarchy.
  • Do not ignore plan drift — schedule regular terraform plan runs 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能