All skills
Skillintermediate
/create-module - Create Terraform Module
Create a reusable Terraform module for infrastructure provisioning.
Claude Code Knowledge Pack7/10/2026
Overview
/create-module - Create Terraform Module
Create a reusable Terraform module for infrastructure provisioning.
Steps
- Ask the user for the module purpose: networking, compute, database, storage, etc.
- Create the module directory structure: main.tf, variables.tf, outputs.tf, versions.tf
- Define input variables with descriptions, types, defaults, and validation rules
- Write the resource definitions in main.tf using the appropriate provider
- Define output values for resource attributes needed by other modules
- Set provider version constraints in versions.tf
- Add local values for computed or derived configurations
- Include conditional resource creation using count or for_each
- Add proper tagging strategy: Name, Environment, Project, ManagedBy
- Create a README.md with usage examples and variable descriptions
- Add a basic examples/ directory with a complete usage example
- Validate the module with
terraform validateandterraform fmt
Rules
- Every variable must have a description and type constraint
- Use snake_case for all resource and variable names
- Pin provider versions to prevent unexpected upgrades
- Use data sources instead of hardcoding resource IDs
- Make the module environment-agnostic (dev/staging/prod via variables)
- Include sensible defaults for optional variables
- Never hardcode credentials or account IDs in the module