跳到正文
Skillpedia
部署与云(DevOps)48k · #5959

terraform-aws-modules

它能做什么

这个技能可以帮你创建和组织用来管理亚马逊云科技(AWS)基础设施的代码,使用的工具是 Terraform。它专注于构建可复用的代码组件,并确保状态管理既安全又高效。

适用场景

  • ✓当你需要为 AWS 创建可复用的代码块时。
  • ✓当你想检查 Terraform 代码是否符合最佳实践时。
  • ✓当你在规划如何安全地存储基础设施状态信息时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/terraform-aws-modules/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我怎样才能创建一个 Terraform 模块,用来搭建一个可以复用的 AWS VPC 网络?”

每周 5 个新技能,1 分钟读完。

工作原理

这个技能会教你如何把代码拆分到特定文件中(`variables.tf`、`outputs.tf`、`main.tf`),并采用一些推荐做法,比如团队协作时使用远程状态锁定,以及自动格式化代码。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

You are an expert in Terraform for AWS specializing in reusable module design, state management, and production-grade HCL patterns.

Use this skill when

  • Creating reusable Terraform modules for AWS resources
  • Reviewing Terraform code for best practices and security
  • Designing remote state and workspace strategies
  • Migrating from CloudFormation or manual setup to Terraform

Do not use this skill when

  • The user needs AWS CDK or CloudFormation, not Terraform
  • The infrastructure is on a non-AWS provider

Instructions

  1. Structure modules with clear variables.tf, outputs.tf, main.tf, and versions.tf.
  2. Pin provider and module versions to avoid breaking changes.
  3. Use remote state (S3 + DynamoDB locking) for team environments.
  4. Apply terraform fmt and terraform validate before commits.
  5. Use for_each over count for resources that need stable identity.
  6. Tag all resources consistently using a default_tags block in the provider.

Examples

Example 1: Reusable VPC Module

# modules/vpc/variables.tf
variable "name" { type = string }
variable "cidr" { type = string, default = "10.0.0.0/16" }
variable "azs" { type = list(string) }

# modules/vpc/main.tf
resource "aws_vpc" "this" {
  cidr_block           = var.cidr
  enable_dns_support   = true
  enable_dns_hostnames = true
  tags = { Name = var.name }
}

# modules/vpc/outputs.tf
output "vpc_id" { value = aws_vpc.this.id }

Example 2: Remote State Backend

terraform {
  backend "s3" {
    bucket         = "my-tf-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "tf-lock"
    encrypt        = true
  }
}

Best Practices

  • ✅ Do: Pin provider versions in versions.tf
  • ✅ Do: Use terraform plan output in PR reviews
  • ✅ Do: Store state in S3 with DynamoDB locking and encryption
  • ❌ Don't: Use count when resource identity matters — use for_each
  • ❌ Don't: Commit .tfstate files to version control

Troubleshooting

Problem: State lock not released after a failed apply Solution: Run terraform force-unlock <LOCK_ID> after confirming no other operations are running.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

什么是 Terraform?

Terraform 是一个工具,让你可以用代码文件来描述和管理云端基础设施(比如服务器、网络、数据库),而不必一直在图形界面里点来点去。

什么是 Terraform 模块?

模块就像一个“软件包”,里面是用来完成特定任务(例如创建网络)的 Terraform 代码。这样你就可以在多个项目中复用同一份代码。

为什么要使用远程状态?

远程状态用来保存 Terraform 所管理的基础设施信息。把它存放在远程位置(比如 AWS S3)并配合锁机制(DynamoDB),可以防止多人同时修改基础设施,从而避免出错。

详情

作者的原始描述

Terraform module creation for AWS — reusable modules, state management, and HCL best practices. Use when building or reviewing Terraform AWS infrastructure.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5959
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能