claude-skill-hcp-terraform / terraform-style-guide
CLAUDE.md4 starsChanged 13 months agoMITView on GitHub
This skill provides comprehensive guidance on Terraform code style, formatting, and best practices based on HashiCorp's official standards. Use this skill when working with any Terraform configuration to ensure code quality, consistency, and maintainability. Proactively reference this skill when: - Writing new Terraform configurations - Reviewing or refactoring existing Terraform code - Formatting code before commits - Organizing files and directory structures - Establishing or enforcing team coding standards - Resolving style inconsistencies - Setting up version control configurations -…
In this repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- terraform-mcp-as-code/CLAUDE.mdCLAUDE.md
- terraform-stacks/CLAUDE.mdCLAUDE.md
- terraform-test/CLAUDE.mdCLAUDE.md
- Terraform Infrastructure as CodeSkill
- terraform-stacksSkill
- terraform-style-guideSkill
- terraform-testSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
30 rules. About 0 are common, 27 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈27
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Consistency: - All code follows the same formatting and organizational patterns
- Distinctive: line 31
Always recommend running these before committing:
- Distinctive: line 34
Consider Git pre-commit hooks to automate these
- Distinctive: line 45
Use descriptive nouns with underscores (not hyphens)
- Distinctive: line 75
When reviewing Terraform code, check against the style guide:
- Distinctive: line 94
When writing Terraform configurations:
- Distinctive: line 96
Start with file structure: - Create standard files (terraform.tf, providers.tf, main.tf, etc.)
- Distinctive: line 97
Apply formatting rules: - Use proper indentation, alignment, spacing
- Distinctive: line 104
When refactoring existing code:
- Distinctive: line 106
Minimize code changes: - follow bestpractice but focus on achieving outcome.
- Distinctive: line 108
Update variable declarations: - Add missing types and descriptions
- Distinctive: line 112
When initializing a new Terraform project:
- Distinctive: line 123
When providing code examples:
- Distinctive: line 152
Call out these common mistakes:
- Distinctive: line 155
Use tabs for indentation
- Distinctive: line 157
Use hyphens in names
- Very specific: line 159
Use // or /* */ comments
- Distinctive: line 160
Commit state files or .terraform directory
- Distinctive: line 161
Use overly generic names
- Distinctive: line 164
Use 2 spaces for indentation
- Distinctive: line 165
Use descriptive nouns for names
- Distinctive: line 166
Use underscores as separators
- Very specific: line 168
Use # for comments
- Distinctive: line 170
Use specific, meaningful names
- Very specific: line 184
Run terraform fmt before committing
- Distinctive: line 185
All variables need type and description
- Distinctive: line 186
Use descriptive nouns with underscores
- Distinctive: line 187
Follow standard file structure
- Distinctive: line 204
When referencing specific sections, use markdown links:
- Distinctive: line 228
Explain why: - Don't just fix, explain the style principle
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Terraform Style Guide - Claude Code Guidance
Overview
This skill provides comprehensive guidance on Terraform code style, formatting, and best practices based on HashiCorp's official standards. Use this skill when working with any Terraform configuration to ensure code quality, consistency, and maintainability.
When to Apply This Skill
Proactively reference this skill when:
- Writing new Terraform configurations
- Reviewing or refactoring existing Terraform code
- Formatting code before commits
- Organizing files and directory structures
- Establishing or enforcing team coding standards
- Resolving style inconsistencies
- Setting up version control configurations
- Designing module structures
- Implementing testing and validation
Core Concepts
Code Quality Pillars
- Consistency - All code follows the same formatting and organizational patterns
- Readability - Code is easy to understand with clear naming and structure
- Maintainability - Changes are easy to make without breaking functionality
- Scalability - Structure supports growth from simple to complex projects
The Three Fundamental Commands
Always recommend running these before committing:
terraform fmt- Auto-format code to standardsterraform validate- Catch syntax and configuration errors- Consider Git pre-commit hooks to automate these
Key Style Principles to Enforce
Formatting
- 2 spaces for indentation (never tabs)
- Align equals signs for consecutive arguments
- Meta-arguments first (count, for_each), then standard args, then blocks
- Blank lines separate logical groups
Naming
- Use descriptive nouns with underscores (not hyphens)
- Lowercase only
- Exclude resource type from resource names (redundant)
- Examples:
web_server,database_primary,vpc_main
File Organization
Standard files in order of importance:
terraform.tf- Version requirementsproviders.tf- Provider configsmain.tf- Primary resourcesvariables.tf- Input variables (alphabetical)outputs.tf- Output values (alphabetical)locals.tf- Local valuesbackend.tf- State backend config
Resource Organization
- Data sources before resources that reference them
- Dependent resources after their dependencies
- Standard parameter order within resources (meta-arguments → args → blocks → lifecycle → depends_on)
Variables and Outputs
Always require:
typeon all variablesdescriptionon all variables and outputs- Mark
sensitive = truefor secrets
Common Scenarios
Scenario 1: Code Review
When reviewing Terraform code, check against the style guide:
Style Guide Checklist:
- [ ] Code formatted with `terraform fmt`
- [ ] All variables have type and description
- [ ] Resource names use descriptive nouns with underscores
- [ ] Files organized according to standard structure
- [ ] Version constraints pinned
- [ ] Sensitive values marked appropriately
- [ ] .gitignore configured correctlyReference specific sections:
- "See the Naming Conventions section for resource naming"
- "Review Variables and Outputs for required attributes"
Scenario 2: Writing New Code
When writing Terraform configurations:
- Start with file structure - Create standard files (terraform.tf, providers.tf, main.tf, etc.)
- Apply formatting rules - Use proper indentation, alignment, spacing
- Follow naming conventions - Descriptive nouns with underscores
- Add complete metadata - Type and description for all variables
- Organize logically - Data sources first, group related resources
Scenario 3: Refactoring
When refactoring existing code:
- Minimize code changes - follow bestpractice but focus on achieving outcome.
- Run terraform fmt - Auto-fix formatting issues
- Update variable declarations - Add missing types and descriptions
Scenario 4: Setting Up New Project
When initializing a new Terraform project:
- Create standard file structure
- Configure .gitignore properly
- Pin versions in terraform.tf
- Set up provider configurations
- Consider Git hooks for fmt and validate
- Add README with project documentation
Code Examples
When providing code examples:
- Always use proper formatting (2-space indentation, aligned equals)
- Include required attributes (type, description)
- Show before/after for improvements
- Add comments explaining style choices
- Reference specific style guide sections
Example template:
# Good - follows style guide
resource "aws_instance" "web_server" {
# Meta-arguments first
count = var.instance_count
# Standard arguments (aligned)
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
# Blocks last
tags = {
Name = "web-${count.index}"
}
}Anti-Patterns to Avoid
Call out these common mistakes:
❌ Don't:
- Use tabs for indentation
- Include resource type in resource name
- Use hyphens in names
- Skip variable types or descriptions
- Use
//or/* */comments - Commit state files or .terraform directory
- Use overly generic names
✅ Do:
- Use 2 spaces for indentation
- Use descriptive nouns for names
- Use underscores as separators
- Include complete variable metadata
- Use
#for comments - Configure .gitignore properly
- Use specific, meaningful names
Integration with Other Skills
This skill complements:
- terraform-test - Style guide informs test structure and organization
- terraform-stacks - Apply style conventions to terraform stack configurations
- General Terraform development - Foundation for all Terraform work
Quick Reference
Most Important Rules
- Run
terraform fmtbefore committing - All variables need type and description
- Use descriptive nouns with underscores
- Follow standard file structure
- Pin version constraints
File Organization Quick Ref
/
├── terraform.tf # Versions
├── providers.tf # Provider configs
├── main.tf # Resources
├── variables.tf # Inputs (alphabetical)
├── outputs.tf # Outputs (alphabetical)
├── locals.tf # Local valuesReferencing the Style Guide
When referencing specific sections, use markdown links:
- Code Formatting Standards
- Naming Conventions
- File Organization
- Variables and Outputs
- Version Control
Success Criteria
Code following this style guide should:
- ✅ Pass
terraform fmtwithout changes - ✅ Pass
terraform validatewithout errors - ✅ Be immediately readable by any team member
- ✅ Follow consistent patterns throughout
- ✅ Include complete metadata (types, descriptions)
- ✅ Be organized in standard file structure
- ✅ Use meaningful, descriptive names
- ✅ Have proper version constraints
- ✅ Exclude sensitive files from version control
Tips for Claude Code
- Be proactive - Suggest style improvements even when not explicitly asked
- Explain why - Don't just fix, explain the style principle
- Show examples - Provide before/after comparisons
- Reference sections - Point to specific style guide sections
- Use checklists - Help users verify compliance systematically
- Automate - Recommend
terraform fmtand Git hooks - Be consistent - Apply the same standards across all Terraform code
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

