원클릭으로
terraform-best-practices
Comprehensive best practices for Terraform infrastructure as code from Anton Babenko's community guide
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Comprehensive best practices for Terraform infrastructure as code from Anton Babenko's community guide
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
GitBook documentation platform. Use when creating, publishing, or managing docs sites — content structure, blocks, Git Sync, customization, AI search, collaboration, and the GitBook API.
MemPalace local-first AI memory system. Use when setting up persistent memory for Claude Code sessions, mining project files or conversation transcripts, querying past context, configuring MCP tools, managing the knowledge graph, or troubleshooting palace operations.
LangChain AWS integration — ChatBedrockConverse (Claude/Nova/Llama/Mistral on Bedrock), BedrockEmbeddings, AmazonKnowledgeBasesRetriever, BedrockAgentsRunnable, BedrockRerank, BedrockPromptCachingMiddleware, CodeInterpreterToolkit, BrowserToolkit (computer use), Neptune graph chains, and SageMaker endpoint.
LangChain Deep Agents (Python) — build, deploy, and customize stateful long-running agents with virtual filesystems, subagents, human-in-the-loop, and LangSmith observability. Also covers LangGraph, LangChain OSS chains/retrievers, and Agent Server API.
LangChain Exa integration — semantic web search with ExaSearchRetriever (RAG), ExaSearchResults (agent tool), and ExaFindSimilarResults (find similar URLs). Unique features: use_autoprompt (LLM query rewriting), highlights (excerpts), summary (per-result LLM summaries), livecrawl (real-time), and date filtering.
LangChain MCP Adapters — connect LangChain agents to MCP (Model Context Protocol) servers. Load MCP tools, prompts, and resources as LangChain-compatible objects. Supports stdio, SSE, StreamableHTTP, and WebSocket transports. Includes interceptors, callbacks, and multi-server management.
| name | terraform-best-practices |
| version | 1.0.0 |
| description | Comprehensive best practices for Terraform infrastructure as code from Anton Babenko's community guide |
| author | Anton Babenko (terraform-best-practices.com) |
| last_updated | "2026-01-29T00:00:00.000Z" |
| skill_level | intermediate |
| prerequisites | ["Basic Terraform knowledge (resources, variables, outputs)","Understanding of IaC concepts","Familiarity with cloud providers (AWS/Azure/GCP)"] |
| when-to-use | ["Designing Terraform project structure","Implementing infrastructure as code patterns","Scaling Terraform from small to large infrastructures","Choosing between Terraform and Terragrunt workflows","Establishing naming conventions and code styling","Managing Terraform state and modules"] |
Comprehensive community best practices for Terraform infrastructure as code, based on Anton Babenko's widely-adopted guide at terraform-best-practices.com.
Activate this skill when:
Small Infrastructure (< 20 resources)
Medium Infrastructure (20-100 resources)
Large Infrastructure (100+ resources)
Resource Modules
terraform-aws-modules/vpc/awsInfrastructure Modules
Compositions
# 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/
# 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"
}
instance_type, vpc_cidr_blockenable_ or create_: enable_monitoring, create_vpcsubnet_ids, availability_zonesmain.tf - Primary resource definitionsvariables.tf - Input variablesoutputs.tf - Output valuesversions.tf - Provider and Terraform version constraintsdata.tf - Data sources (optional)locals.tf - Local values (optional)# 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
})
}
# 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."
}
}
# 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"
}
}
.tfstate files to version control (contains plaintext secrets)sensitive = true for sensitive outputsterraform_remote_state data source for cross-stack references✅ Small to medium infrastructure (< 50 resources) ✅ Single cloud provider ✅ Few environments (dev/prod) ✅ Team comfortable with DRY through modules
✅ Large infrastructure (100+ resources) ✅ Many environments (dev/staging/prod/dr) ✅ Deep directory hierarchies ✅ Need for inheritance and composition ✅ Complex dependency orchestration
# 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
}
# 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
}
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]
Problem: Circular dependencies between modules, version conflicts Solution:
Problem: "Error acquiring state lock" Solution:
terraform force-unlock cautiously.terraform.lock.hclProblem: Manual changes outside Terraform Solution:
terraform plan regularly in CIterraform refresh to detect driftProblem: Changing count causes resource recreation Solution:
for_each with maps for stable resourcescount 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
}
references/terraform.md for code structure examplesterraform fmt and tflint from day oneComplete documentation extracted from terraform-best-practices.com covering:
Practical examples demonstrating:
Multilingual index of all content (20+ languages available on source website)
# 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
To refresh with latest best practices:
skill-seekers scrape https://www.terraform-best-practices.com/ \
--name terraform-best-practices \
--max-pages 50