Enforces organization-specific Terraform style guides and conventions, providing tools to validate Infrastructure as Code snippets, generate compliant resources with security defaults, and access code examples that follow custom naming, tagging, and module patterns.
tf-dialect
tf-dialect is an MCP (Model Context Protocol) server that exposes your organization's Terraform style guide to AI coding agents, ensuring they generate context-aware, organization-specific Infrastructure as Code instead of generic HCL.
Configure once, use with any MCP-capable coding agent (Claude Desktop, Cline, etc.).
Quick Start
Features
📚 Style Guide Management: Define your Terraform conventions in a single YAML file
🔍 Validation: Check Terraform snippets against your organization's rules
📝 Code Examples: Provide reusable snippets for common patterns
🛡️ Security Defaults: Enforce security best practices automatically
🏗️ Code Generation: Generate compliant Terraform resources
🤖 AI-Native: Works seamlessly with MCP-capable coding agents
Installation
Configuration
Copy the example config:
Edit
terraform-style.yamlto match your organization's standards:
Running the Server
Standalone
With Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
Or if terraform-style.yaml is in the same directory as the server:
With Cline VSCode Extension
Add to your MCP settings:
MCP Tools
The server exposes four tools that AI agents can use:
1. get_style_guide
Get the complete Terraform style guide configuration.
Input: None
Output:
Example agent prompt:
"Show me the Terraform style guide for this project"
2. list_examples
List code examples, optionally filtered by resource type or search term.
Input:
Output:
Example agent prompts:
"Show me examples of S3 buckets" "List all RDS examples"
3. validate_snippet
Validate Terraform code against the style guide.
Input:
Output:
Example agent prompts:
"Validate this Terraform code against our style guide" "Check if this S3 bucket configuration is compliant"
4. generate_resource
Generate a Terraform resource following organization standards.
Input:
Output:
Supported resource types:
aws_s3_bucketaws_db_instanceOthers (generates generic stub with TODOs)
Example agent prompts:
"Generate an S3 bucket for prod analytics logs" "Create an RDS instance for the staging API database"
Validation Rules
tf-dialect enforces the following rules:
Required Tags
Ensures all resources include required tags defined in your config.
Forbidden Patterns
Blocks dangerous patterns like:
0.0.0.0/0in security groupsHardcoded credentials
Custom regex patterns you define
Security Defaults
Enforces security best practices:
S3 Buckets:
Block public access
Enable versioning
Enable encryption (KMS or AES256)
RDS Instances:
Enable storage encryption
Set backup retention period
Other configurable defaults
Naming Conventions
Validates resource names follow your format:
<project>-<env>-<component>-<extra?>Checks component count and structure
Development
Example Workflow
Agent asks about style:
Agent calls
get_style_guideLearns your organization's conventions
Agent needs an example:
Agent calls
list_exampleswithresourceType: "rds"Gets working RDS configuration examples
Agent generates code:
Agent calls
generate_resourceor writes codeThen calls
validate_snippetto check compliance
Agent fixes violations:
Reads violation suggestions
Updates code to be compliant
Use Cases
Onboarding: New team members' AI assistants learn your standards instantly
Consistency: All Terraform code follows the same patterns across teams
Security: Enforce security defaults automatically in generated code
Productivity: AI generates compliant code on first try, not generic HCL
License
MIT
Contributing
Contributions welcome! This is an OSS-friendly project designed for IaC power users.
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Exposes your organization's Terraform style guide to AI coding agents, enabling them to generate, validate, and ensure Infrastructure as Code follows your specific conventions, naming standards, security defaults, and best practices.