comeonoliver/skillshub/terraform-skill
Claude Code and agent skill by comeonoliver/skillshub
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Install
npx vskill@latest install comeonoliver/skillshub/terraform-skillSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as comeonoliver/skillshub/terraform-skill.
Terraform Skill for Claude
Comprehensive Terraform and OpenTofu guidance covering testing, modules, CI/CD, and production patterns. Based on terraform-best-practices.com and enterprise experience.
When to Use This Skill
Activate this skill when:
- Creating new Terraform or OpenTofu configurations or modules
- Setting up testing infrastructure for IaC code
- Deciding between testing approaches (validate, plan, frameworks)
- Structuring multi-environment deployments
- Implementing CI/CD for infrastructure-as-code
- Reviewing or refactoring existing Terraform/OpenTofu projects
- Choosing between module patterns or state management approaches
Don't use this skill for:
- Basic Terraform/OpenTofu syntax questions (Claude knows this)
- Provider-specific API reference (link to docs instead)
- Cloud platform questions unrelated to Terraform/OpenTofu
Core Principles
1. Code Structure Philosophy
Module Hierarchy:
| Type | When to Use | Scope | |
|---|---|---|---|
| Resource Module | Single logical group of connected resources | VPC + subnets, Security group + rules | |
| Infrastructure Module | Collection of resource modules for a purpose | Multiple resource modules in one region/account | |
| Composition | Complete infrastructure | Spans multiple regions/accounts |
Hierarchy: Resource → Resource Module → Infrastructure Module → Composition
Directory Structure:
Key principle from terraform-best-practices.com:
- Separate environments (prod, staging) from modules (reusable components)
- Use examples/ as both documentation and integration test fixtures
- Keep modules small and focused (single responsibility)
For detailed module architecture, see: Code Patterns: Module Types & Hierarchy
2. Naming Conventions
Resources:
Singleton Resources:
Use "this" when your module creates only one resource of that type:
✅ DO:
❌ DON'T use "this" for multiple resources:
Use descriptive names when creating multiple resources of the same type.
Variables:
Files:
main.tf- Primary resourcesvariables.tf- Input variablesoutputs.tf- Output valuesversions.tf- Provider versionsdata.tf- Data sources (optional)
Testing Strategy Framework
Decision Matrix: Which Testing Approach?
| Your Situation | Recommended Approach | Tools | Cost | |
|---|---|---|---|---|
| Quick syntax check | Static analysis | terraform validate, fmt | Free | |
| Pre-commit validation | Static + lint | validate, tflint, trivy, checkov | Free | |
| Terraform 1.6+, simple logic | Native test framework | Built-in terraform test | Free-Low | |
| Pre-1.6, or Go expertise | Integration testing | Terratest | Low-Med | |
| Security/compliance focus | Policy as code | OPA, Sentinel | Free | |
| Cost-sensitive workflow | Mock providers (1.7+) | Native tests + mocking | Free | |
| Multi-cloud, complex | Full integration | Terratest + real infra | Med-High |
Testing Pyramid for Infrastructure
Native Test Best Practices (1.6+)
Before generating test code:
- Validate schemas with Terraform MCP:
`` Search provider docs → Get resource schema → Identify block types ``
- Choose correct command mode:
command = plan- Fast, for input validationcommand = apply- Required for computed values and set-type blocks
- Handle set-type blocks correctly:
- Cannot index with
[0] - Use
forexpressions to iterate - Or use
command = applyto materialize
Common patterns:
- S3 encryption rules: set (use for expressions)
- Lifecycle transitions: set (use for expressions)
- IAM policy statements: set (use for expressions)
For detailed testing guides, see:
- [Testing Frameworks Guide](references/testing-frameworks.md) - Deep dive into static analysis, native tests, and Terratest
- [Quick Reference](references/quick-reference.md#testing-approach-selection) - Decision flowchart and command cheat sheet
Code Structure Standards
Resource Block Ordering
Strict ordering for consistency:
countorfor_eachFIRST (blank line after)- Other arguments
tagsas last real argumentdepends_onafter tags (if needed)lifecycleat the very end (if needed)
Variable Block Ordering
description(ALWAYS required)typedefaultvalidationnullable(when setting to false)
For complete structure guidelines, see: Code Patterns: Block Ordering & Structure
Count vs For_Each: When to Use Each
Quick Decision Guide
| Scenario | Use | Why | |
|---|---|---|---|
| Boolean condition (create or don't) | count = condition ? 1 : 0 | Simple on/off toggle | |
| Simple numeric replication | count = 3 | Fixed number of identical resources | |
| Items may be reordered/removed | for_each = toset(list) | Stable resource addresses | |
| Reference by key | for_each = map | Named access to resources | |
| Multiple named resources | for_each | Better maintainability |
Common Patterns
Boolean conditions:
Stable addressing with for_each:
For migration guides and detailed examples, see: Code Patterns: Count vs For_Each
Locals for Dependency Management
Use locals to ensure correct resource deletion order:
Why this matters:
- Prevents deletion errors when destroying infrastructure
- Ensures correct dependency order without explicit
depends_on - Particularly useful for VPC configurations with secondary CIDR blocks
For detailed examples, see: Code Patterns: Locals for Dependency Management
Module Development
Standard Module Structure
Best Practices Summary
Variables:
- ✅ Always include
description - ✅ Use explicit
typeconstraints - ✅ Provide sensible
defaultvalues where appropriate - ✅ Add
validationblocks for complex constraints - ✅ Use
sensitive = truefor secrets
Outputs:
- ✅ Always include
description - ✅ Mark sensitive outputs with
sensitive = true - ✅ Consider returning objects for related values
- ✅ Document what consumers should do with each output
For detailed module patterns, see:
- [Module Patterns Guide](references/module-patterns.md) - Variable best practices, output design, ✅ DO vs ❌ DON'T patterns
- [Quick Reference](references/quick-reference.md#common-patterns) - Resource naming, variable naming, file organization
CI/CD Integration
Recommended Workflow Stages
- Validate - Format check + syntax validation + linting
- Test - Run automated tests (native or Terratest)
- Plan - Generate and review execution plan
- Apply - Execute changes (with approvals for production)
Cost Optimization Strategy
- Use mocking for PR validation (free)
- Run integration tests only on main branch (controlled cost)
- Implement auto-cleanup (prevent orphaned resources)
- Tag all test resources (track spending)
For complete CI/CD templates, see:
- [CI/CD Workflows Guide](references/ci-cd-workflows.md) - GitHub Actions, GitLab CI, Atlantis integration, cost optimization
- [Quick Reference](references/quick-reference.md#troubleshooting-guide) - Common CI/CD issues and solutions
Security & Compliance
Essential Security Checks
Common Issues to Avoid
❌ Don't:
- Store secrets in variables
- Use default VPC
- Skip encryption
- Open security groups to 0.0.0.0/0
✅ Do:
- Use AWS Secrets Manager / Parameter Store
- Create dedicated VPCs
- Enable encryption at rest
- Use least-privilege security groups
For detailed security guidance, see:
- [Security & Compliance Guide](references/security-compliance.md) - Trivy/Checkov integration, secrets management, state file security, compliance testing
Version Management
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/antonbabenko/terraform-skill/terraform-skill/SKILL.md
Popularity
- Repository stars
- 66
- Repository forks
- 24
- 7-day trend score
- 26
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
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/comeonoliver/skillshub/terraform-skill)