Skillshub building-terraform-modules
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/jeremylongshore/claude-code-plugins-plus-skills/building-terraform-modules" ~/.claude/skills/comeonoliver-skillshub-building-terraform-modules && rm -rf "$T"
manifest:
skills/jeremylongshore/claude-code-plugins-plus-skills/building-terraform-modules/SKILL.mdsource content
Building Terraform Modules
Overview
Build reusable, production-ready Terraform modules with proper variable definitions, outputs, validation rules, documentation, and examples. Generate modules following HashiCorp's standard module structure for AWS, GCP, and Azure resources with security best practices, tagging conventions, and lifecycle management.
Prerequisites
- Terraform 1.0+ installed (
)terraform version - Cloud provider credentials configured for the target platform
- Understanding of the infrastructure resources the module will manage
- Familiarity with HCL syntax and Terraform module conventions
installed for automated documentation generation (optional)terraform-docs
Instructions
- Define the module scope: determine which cloud resources the module manages and its input/output contract
- Create the standard module file structure:
,main.tf
,variables.tf
,outputs.tf
,versions.tflocals.tf - Write
withversions.tf
andrequired_version
blocks pinned to stable versionsrequired_providers - Define input variables in
with descriptions, types, defaults, and validation rulesvariables.tf - Implement resources in
using variables for all configurable values; usemain.tf
for computed valueslocals - Add meaningful outputs in
for resource IDs, ARNs, endpoints, and connection stringsoutputs.tf - Implement security defaults: encryption enabled, public access blocked, least-privilege IAM, logging enabled
- Create an
directory with at least one complete usage example showing module invocationexamples/ - Generate documentation with
terraform-docs markdown table . > README.md - Validate the module with
and test withterraform init && terraform validate
using the exampleterraform plan
Output
- Module files:
,main.tf
,variables.tf
,outputs.tf
,versions.tflocals.tf - Example usage in
with realistic variable valuesexamples/basic/main.tf - Auto-generated
with inputs, outputs, and usage documentationREADME.md
configuration for documentation generation.terraform-docs.yml- Optional: test files using Terratest or
(HCL-based)terraform test
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Input value does not meet validation rule | Check the block in ; adjust the value or the validation regex |
| Missing or wrong provider source in | Add the provider to with correct source and version constraint |
| Resources referencing each other in a loop | Refactor to break the cycle; use or separate into sub-modules |
| Typo in resource name or resource removed | Verify resource names in match output references exactly |
| Incorrect module path or registry reference | Verify the path is relative (e.g., ) or a valid registry address |
Examples
- "Build a Terraform module for an AWS VPC with configurable CIDR, public/private subnets across 3 AZs, NAT gateway, and flow logs."
- "Create a GCP Cloud Run module with custom domain, IAM bindings, and auto-scaling configuration as input variables."
- "Generate a Terraform module for an S3 bucket with versioning, encryption, lifecycle rules, and access logging, with all settings as optional variables with secure defaults."
Resources
- Terraform module registry: https://registry.terraform.io/
- Module structure guide: https://developer.hashicorp.com/terraform/language/modules/develop/structure
- terraform-docs: https://terraform-docs.io/
- Module best practices: https://developer.hashicorp.com/terraform/language/modules/develop