Token导航 LogoToken导航

Agent Skill · 开发规范

terraform-best-practices(Terraform 最佳实践)

用于辅助云资源、部署、容器、基础设施和运维自动化任务。它适合让 Agent 检查配置、整理部署步骤、分析资源状态、生成排障思路或辅助云服务接入。使用时需要明确目标环境、账号权限、区域和资源组,区分本地测试与生产操作;涉及删除资源、重启服务、修改网络或权限配置时,应先确认影响范围。

terraform-best-practices 是开发规范类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为调用外部服务;许可证信息还不明确,第三方扫描已通过,按安装量在开发规范类的 1,265 个 Skill 里排第 1,082。

总安装 247周安装 10GitHub Stars 11下载 78核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:terraform-best-practices(Terraform 最佳实践)
来源仓库:https://github.com/enuno/claude-command-and-control
仓库路径:skills/terraform-best-practices
安装命令:
npx skills add https://github.com/enuno/claude-command-and-control --skill terraform-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/enuno/claude-command-and-control --skill terraform-best-practices

这个 Skill 是做什么的

开发规范类 Skill 用来统一代码风格、目录结构和评审口径,产出多为检查清单或改写建议。

terraform-best-practices 提供 IaC 基础设施即代码最佳实践,覆盖项目结构、模块复用和状态管理。基于社区成熟方案整理,适用于多云部署、环境隔离和资源生命周期控制场景。可在设计阶段或扩展规模时启用,辅助制定可审计、易复用的云资源配置策略。

涉及生产环境变更前务必确认账号权限和回滚预案,防止误删关键资源。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/terraform-best-practices

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/enuno/claude-command-and-control --skill terra…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要调用外部服务,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

terraform-best-practices 怎么安装?

在终端执行 npx skills add https://github.com/enuno/claude-command-and-control --skill terraform-best-…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

terraform-best-practices 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

terraform-best-practices 需要什么权限?

权限级别是调用外部服务。该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

terraform-best-practices 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

terraform-best-practices 用的人多吗?

公开数据是累计安装 247 次,近一周安装 10 次,下载 78 次,GitHub 11 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

terraform-best-practices 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发规范类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发规范类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
vercel-react-best-practices

Vercel React 最佳实践 · Codex、Claude

8,490,72025,918操作浏览器MIT通过
web-design-guidelines

网页设计指南 · Codex、Claude

6,686,01625,885需要联网MIT有提醒
remotion-best-practices

Remotion 最佳实践 · Codex、Claude

6,505,6323,027操作浏览器MIT有提醒
supabase-postgres-best-practices

Supabase Postgres 最佳实践 · Codex、Claude

3,175,5232,030需要联网MIT通过
next-best-practices

Next.js 最佳实践 · Codex、Claude

1,848,240841操作浏览器MIT通过
terraform-best-practices

Terraform 最佳实践 · 本页

24711调用外部服务未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Terraform Best Practices Skill

Comprehensive community best practices for Terraform infrastructure as code, based on Anton Babenko's widely-adopted guide at terraform-best-practices.com.

When to Use This Skill

Activate this skill when:

  • Designing project structure - Choosing how to organize Terraform code for small, medium, or large infrastructure
  • Implementing IaC patterns - Following community best practices for modules, compositions, and state management
  • Scaling infrastructure - Growing from simple setups to complex multi-environment deployments
  • Evaluating tools - Deciding between vanilla Terraform vs Terragrunt orchestration
  • Establishing standards - Creating team conventions for naming, styling, and code organization
  • Troubleshooting common issues - Resolving frequent Terraform problems (dependency hell, state management, etc.)

Key Concepts

Infrastructure Sizes & Patterns

Small Infrastructure (< 20 resources)

  • Single Terraform directory
  • Minimal module structure
  • Direct resource definitions
  • Simple state management

Medium Infrastructure (20-100 resources)

  • Multiple environment directories
  • Reusable modules
  • Remote state backend
  • Workspaces or directory-based environments

Large Infrastructure (100+ resources)

  • Module composition approach
  • Terragrunt for orchestration
  • Hierarchical state structure
  • Infrastructure vs resource modules

Module Types

Resource Modules

  • Create individual AWS/Azure/GCP resources
  • Highly reusable across projects
  • Published to registries
  • Examples: terraform-aws-modules/vpc/aws

Infrastructure Modules

  • Combine resource modules
  • Environment-specific configurations
  • Less portable, more opinionated
  • Example: Company VPC + security groups + bastion

Compositions

  • Top-level infrastructure assembly
  • Orchestrate multiple modules
  • Environment-specific values
  • No reusable logic, only wiring

Code Structure Patterns

# Small Infrastructure
terraform/
  main.tf
  variables.tf
  outputs.tf
  terraform.tfvars

# Medium Infrastructure
terraform/
  modules/
    vpc/
    compute/
  environments/
    dev/
    prod/

# Large Infrastructure (Terragrunt)
infrastructure/
  _global/
  dev/
    vpc/
      terragrunt.hcl
    compute/
      terragrunt.hcl
  prod/
    vpc/
    compute/

Naming Conventions

Resource Naming

# Pattern: {project}-{environment}-{resource-type}-{name}
resource "aws_s3_bucket" "main" {
  bucket = "myapp-prod-data-customer-uploads"
}

# Pattern: this for single resource of type
resource "aws_security_group" "this" {
  name = "${var.project}-${var.environment}-app"
}

Variable Naming

  • Use snake_case: instance_type, vpc_cidr_block
  • Boolean prefix with enable_ or create_: enable_monitoring, create_vpc
  • Plural for lists: subnet_ids, availability_zones

File Organization

  • main.tf - Primary resource definitions
  • variables.tf - Input variables
  • outputs.tf - Output values
  • versions.tf - Provider and Terraform version constraints
  • data.tf - Data sources (optional)
  • locals.tf - Local values (optional)

Code Styling Best Practices

Formatting

# Use terraform fmt
# Group related settings
resource "aws_instance" "web" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = var.instance_type

  tags = {
    Name        = "${var.project}-web"
    Environment = var.environment
    ManagedBy   = "Terraform"
  }
}

# Align equals signs in blocks
variable "instance_config" {
  type = object({
    instance_type = string
    volume_size   = number
    volume_type   = string
  })
}

Module Structure

# versions.tf - Pin versions
terraform {
  required_version = ">= 1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

# variables.tf - Document everything
variable "vpc_cidr" {
  description = "CIDR block for VPC"
  type        = string
  default     = "10.0.0.0/16"

  validation {
    condition     = can(cidrhost(var.vpc_cidr, 0))
    error_message = "Must be valid IPv4 CIDR."
  }
}

State Management

Backend Configuration

# Use remote state for team collaboration
terraform {
  backend "s3" {
    bucket         = "myapp-terraform-state"
    key            = "prod/vpc/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "terraform-state-lock"
  }
}

State Best Practices

  • Never commit .tfstate files to version control (contains plaintext secrets)
  • Use remote backend (S3, Azure Storage, GCS) with locking
  • CRITICAL: State files contain sensitive data (passwords, keys, IPs)

- Enable versioning on backend storage for rollback capability - Restrict access via IAM policies (least privilege principle) - Consider using sensitive = true for sensitive outputs

  • Separate state files by environment and component
  • Use state file encryption at rest (AES-256)
  • Implement state file backups and disaster recovery procedures
  • Use terraform_remote_state data source for cross-stack references

Terraform vs Terragrunt

When to Use Vanilla Terraform

✅ Small to medium infrastructure (< 50 resources) ✅ Single cloud provider ✅ Few environments (dev/prod) ✅ Team comfortable with DRY through modules

When to Use Terragrunt

✅ Large infrastructure (100+ resources) ✅ Many environments (dev/staging/prod/dr) ✅ Deep directory hierarchies ✅ Need for inheritance and composition ✅ Complex dependency orchestration

Terragrunt Benefits

  • DRY backend configuration
  • Dependency orchestration
  • Variable inheritance
  • Before/after hooks
  • Auto-init and auto-retry

Recommended Tools

Essential

  • terraform - Core IaC tool
  • terraform fmt - Code formatter (built-in)
  • terraform validate - Syntax validator (built-in)

Quality & Linting

  • tflint - Terraform linter with provider-specific rules
  • tfsec - Security scanner for Terraform code
  • checkov - Policy-as-code scanner
  • terraform-docs - Auto-generate documentation

Version Management

  • tfenv - Terraform version manager (like nvm for Node)
  • tgenv - Terragrunt version manager

Workflow Automation

  • pre-commit-terraform - Git hooks for quality gates
  • Atlantis - Pull request automation for Terraform
  • Infracost - Cost estimation in PRs

Orchestration

  • Terragrunt - DRY orchestration wrapper
  • Terramate - Stack orchestration and code generation

Common Patterns

Multi-Environment Setup

# environments/dev/main.tf
module "infrastructure" {
  source = "../../modules/infrastructure"

  environment    = "dev"
  instance_type  = "t3.micro"
  instance_count = 1
}

# environments/prod/main.tf
module "infrastructure" {
  source = "../../modules/infrastructure"

  environment    = "prod"
  instance_type  = "t3.large"
  instance_count = 3
}

Module Composition

# modules/infrastructure/main.tf
module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"

  name = "${var.project}-${var.environment}"
  cidr = var.vpc_cidr
}

module "security_group" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "~> 5.0"

  name   = "${var.project}-${var.environment}-app"
  vpc_id = module.vpc.vpc_id
}

Conditional Resources

resource "aws_instance" "bastion" {
  count = var.create_bastion ? 1 : 0

  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"
}

# Access with: aws_instance.bastion[0]

Frequent Terraform Problems (FTP)

Dependency Hell

Problem: Circular dependencies between modules, version conflicts Solution:

  • Pin provider and module versions explicitly
  • Use Dependabot for automated updates
  • Implement testing for version upgrades
  • Avoid cross-module dependencies; use data sources instead

State Lock Issues

Problem: "Error acquiring state lock" Solution:

  • Implement DynamoDB table for S3 backend locking
  • Use terraform force-unlock cautiously
  • Never delete .terraform.lock.hcl

Resource Drift

Problem: Manual changes outside Terraform Solution:

  • Run terraform plan regularly in CI
  • Use terraform refresh to detect drift
  • Implement policy-as-code (OPA, Sentinel)
  • Restrict manual changes via IAM policies

Count vs For_Each

Problem: Changing count causes resource recreation Solution:

  • Prefer for_each with maps for stable resources
  • Use count only for simple on/off toggles
# Bad - index changes cause recreation
resource "aws_subnet" "example" {
  count      = length(var.azs)
  cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index)
}

# Good - stable keys prevent recreation with explicit mapping
locals {
  az_cidrs = {
    "us-east-1a" = cidrsubnet(var.vpc_cidr, 8, 0)
    "us-east-1b" = cidrsubnet(var.vpc_cidr, 8, 1)
    "us-east-1c" = cidrsubnet(var.vpc_cidr, 8, 2)
  }
}

resource "aws_subnet" "example" {
  for_each          = local.az_cidrs
  availability_zone = each.key
  cidr_block        = each.value
}

Working with This Skill

For Beginners

  1. Start with the Small Infrastructure pattern
  2. Read references/terraform.md for code structure examples
  3. Review naming conventions before writing code
  4. Use terraform fmt and tflint from day one

For Scaling Up

  1. Review Medium Infrastructure patterns when hitting 20+ resources
  2. Evaluate Terragrunt when managing 3+ environments
  3. Implement module composition for reusability
  4. Set up remote state and locking

For Production Readiness

  1. Pin all provider and module versions
  2. Implement pre-commit hooks for quality gates
  3. Use Atlantis or similar for PR-based workflows
  4. Add security scanning (tfsec, checkov) to CI/CD
  5. Set up cost estimation (Infracost)

Reference Files

references/terraform.md

Complete documentation extracted from terraform-best-practices.com covering:

  • Code structure patterns for all infrastructure sizes
  • Module types and composition strategies
  • Real-world examples from small to large setups
  • Tool recommendations and integration guides

references/examples.md

Practical examples demonstrating:

  • Small/medium/large infrastructure implementations
  • Terraform vs Terragrunt comparisons
  • Module composition patterns
  • Environment-specific configurations

references/llms.md

Multilingual index of all content (20+ languages available on source website)

Quick Reference Commands

# Initialize and validate
terraform init
terraform validate
terraform fmt -recursive

# Plan and apply
terraform plan -out=tfplan
terraform apply tfplan

# State management
terraform state list
terraform state show aws_instance.web
terraform state mv aws_instance.old aws_instance.new

# Workspace management
terraform workspace list
terraform workspace select dev
terraform workspace new staging

# Import existing resources
terraform import aws_instance.web i-1234567890abcdef0

# Debugging
TF_LOG=DEBUG terraform apply
terraform console  # Interactive evaluation

Additional Resources

Notes

  • This skill represents community best practices (Anton Babenko), not official HashiCorp documentation
  • Content is based on Terraform 1.0+ patterns and recommendations
  • Focuses on AWS examples but principles apply to all providers
  • Reference files extracted from multilingual source (English content emphasized)

Updating This Skill

To refresh with latest best practices:

skill-seekers scrape https://www.terraform-best-practices.com/ \
  --name terraform-best-practices \
  --max-pages 50

平台分布

Codex

31.76%
按下载量换算25

Claude

29.46%
按下载量换算23

Cursor

19.89%
按下载量换算16

Gemini CLI

10.23%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

调用外部服务

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills