enuno/claude-command-and-control/terraform-best-practices
Claude Code and agent skill by enuno/claude-command-and-control
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Comprehensive best practices for Terraform infrastructure as code from Anton Babenko's community guide
Install
npx vskill@latest install enuno/claude-command-and-control/terraform-best-practicesSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
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
Naming Conventions
Resource Naming
Variable Naming
- Use snake_case:
instance_type,vpc_cidr_block - Boolean prefix with
enable_orcreate_:enable_monitoring,create_vpc - Plural for lists:
subnet_ids,availability_zones
File Organization
main.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)
Code Styling Best Practices
Formatting
Module Structure
State Management
Backend Configuration
State Best Practices
- Never commit
.tfstatefiles 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 = truefor 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_statedata 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
Module Composition
Conditional Resources
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-unlockcautiously - Never delete
.terraform.lock.hcl
Resource Drift
Problem: Manual changes outside Terraform Solution:
- Run
terraform planregularly in CI - Use
terraform refreshto 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_eachwith maps for stable resources - Use
countonly for simple on/off toggles
Working with This Skill
For Beginners
- Start with the Small Infrastructure pattern
- Read
references/terraform.mdfor code structure examples - Review naming conventions before writing code
- Use
terraform fmtandtflintfrom day one
For Scaling Up
- Review Medium Infrastructure patterns when hitting 20+ resources
- Evaluate Terragrunt when managing 3+ environments
- Implement module composition for reusability
- Set up remote state and locking
For Production Readiness
- Pin all provider and module versions
- Implement pre-commit hooks for quality gates
- Use Atlantis or similar for PR-based workflows
- Add security scanning (tfsec, checkov) to CI/CD
- 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
Additional Resources
- Source: terraform-best-practices.com (Anton Babenko)
- Workshop: GitHub Workshop
- Community Modules: Terraform AWS Modules
- Official Docs: developer.hashicorp.com/terraform
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
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/terraform-best-practices/SKILL.md
Popularity
- Repository stars
- 11
- Repository forks
- 2
- 7-day trend score
- 12
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 30 Mar 2026, 7 months ago.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/enuno/claude-command-and-control/terraform-best-practices)