Terraform Infrastructure as Code
БесплатноБез исполняемых скриптовНе проверенProduction-grade Terraform development with HCL best practices, module design, state management, multi-cloud patterns, and AI-enhanced infrastructure as code…
Об этом скилле
Terraform Infrastructure as Code
Overview
This skill provides comprehensive guidance for building production-grade infrastructure with Terraform following 2024-2025 best practices. Terraform is the industry standard for Infrastructure as Code (IaC), enabling version-controlled, reproducible, and automated cloud infrastructure management across AWS, Azure, GCP, and 100+ providers.
When to Use This Skill
Use this skill when:
- Provisioning cloud infrastructure (compute, storage, networking, databases)
- Managing multi-environment deployments (dev, staging, production)
- Implementing immutable infrastructure patterns
- Orchestrating complex multi-cloud architectures
- Automating infrastructure changes with CI/CD pipelines
- Creating reusable infrastructure modules for teams
- Migrating from manual cloud console provisioning to IaC
Core Principles
1. State Management is Critical
Terraform state is the source of truth - protect it
# CORRECT: Remote state with locking
terraform {
backend "s3" {
bucket = "myapp-terraform-state"
key = "prod/vpc/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-state-lock" # Prevents concurrent modifications
# State versioning for recovery
versioning = true
}
}
# WRONG: Local state in production
# terraform {
# backend "local" {
# path = "terraform.tfstate" # Never use local state in teams!
# }
# }
State Best Practices:
- ✅ Always use remote state backends (S3, Azure Blob, GCS, Terraform Cloud)
- ✅ Enable state locking to prevent concurrent runs
- ✅ Enable encryption at rest for sensitive data
- ✅ Use versioning for state file recovery
- ✅ Separate state files per environment and major component
- ❌ Never commit
.tfstatefiles to version control - ❌ Never share state files via email or Slack
2. Module Design for Reusability
Build composable, tested modules with clear interfaces
# modules/vpc/main.tf - Well-designed module
variable "vpc_cidr" {
description = "CIDR block for VPC"
type = string
validation {
condition = can(cidrhost(var.vpc_cidr, 0))
error_message = "VPC CIDR must be valid IPv4 CIDR block"
}
}
variable "environment" {
description = "Environment name (dev, staging, prod)"
type = string
validation {
condition = contains(["dev", "staging", "prod"], var.environment)
error_message = "Environment must be dev, staging, or prod"
}
}
variable "tags" {
description = "Additional tags for all resources"
type = map(string)
default = {}
}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = merge(
{
Name = "${var.environment}-vpc"
Environment = var.environment
ManagedBy = "Terraform"
},
var.tags
)
}
output "vpc_id" {
description = "ID of the created VPC"
value = aws_vpc.main.id
}
output "vpc_cidr" {
description = "CIDR block of the VPC"
value = aws_vpc.main.cidr_block
}
# Usage in root module
module "vpc" {
source = "./modules/vpc"
vpc_cidr = "10.0.0.0/16"
environment = "prod"
tags = {
Team = "platform"
Project = "myapp"
}
}
Module Design Checklist:
- ✅ Single responsibility - one purpose per module
- ✅ Input validation with variable validation blocks
- ✅ Descriptive variable names and descriptions
- ✅ Sensible defaults where appropriate
- ✅ Outputs for all important resource attributes
- ✅ README.md with examples and terraform-docs
- ✅ Versioning for published modules
3. Resource Naming and Tagging
Consistent naming prevents confusion and enables automation
locals {
# Standardized naming convention
name_prefix = "${var.project}-${var.environment}"
# Common tags applied to all resources
common_tags = {
Project = var.project
Environment = var.environment
ManagedBy = "Terraform"
Team = var.team
CostCenter = var.cost_center
CreatedAt = timestamp()
}
}
resource "aws_instance" "app_server" {
# Clear, consistent naming
ami = var.ami_id
instance_type = var.instance_type
tags = merge(
local.common_tags,
{
Name = "${local.name_prefix}-app-server"
Role = "application"
}
)
}
resource "aws_s3_bucket" "data" {
# DNS-compliant naming
bucket = "${local.name_prefix}-data-${data.aws_caller_identity.current.account_id}"
tags = merge(
local.common_tags,
{
Name = "${local.name_prefix}-data-bucket"
DataClass = "sensitive"
Encryption = "required"
}
)
}
Naming Conventions:
- Use lowercase with hyphens:
myapp-prod-web-server - Include environment:
dev-,staging-,prod- - Add resource type suffix:
-vpc,-subnet,-sg - Ensure uniqueness where required (S3 buckets)
4. Data Sources vs Resources
**Use data s
Установить Terraform Infrastructure as Code в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Terraform Infrastructure as Code?
Production-grade Terraform development with HCL best practices, module design, state management, multi-cloud patterns, and AI-enhanced infrastructure as code for scalable cloud deployments
Как установить скилл Terraform Infrastructure as Code?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Terraform Infrastructure as Code запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic