Building terraform modules

From jeremylongshore/claude-code-plugins-plus-skills · View interactive version

Building terraform modules is an AI agent skill from the GitHub repository jeremylongshore/claude-code-plugins-plus-skills. Execute this skill empowers AI assistant to build reusable terraform modules based on user specifications. it leverages the terraform-module-builder plugin to generate production-ready, well-documented terraform module code, incorporating best practices for sec... Use when appropriate context detect

How to use this skill

Skill file

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

Instructions

  1. Define the module scope: determine which cloud resources the module manages and its input/output contract
  2. Create the standard module file structure: main.tf, variables.tf, outputs.tf, versions.tf, locals.tf
  3. Write versions.tf with required_version and required_providers blocks pinned to stable versions
  4. Define input variables in variables.tf with descriptions, types, defaults, and validation rules
  5. Implement resources in main.tf using variables for all configurable values; use locals for computed values
  6. Add meaningful outputs in outputs.tf for resource IDs, ARNs, endpoints, and connection strings
  7. Implement security defaults: encryption enabled, public access blocked, least-privilege IAM, logging enabled
  8. Create an examples/ directory with at least one complete usage example showing module invocation
  9. Generate documentation with terraform-docs markdown table . > README.md
  10. Validate the module with terraform init && terraform validate and test with terraform plan using the example

Output

Error Handling

| Error | Cause | Solution |

|-------|-------|---------|

| variable validation failed | Input value does not meet validation rule | Check the validation block in variables.tf; adjust the value or the validation regex |

| provider not found | Missing or wrong provider source in versions.tf | Add the provider to required_providers with correct source and version constraint |

| circular dependency | Resources referencing each other in a loop | Refactor to break the cycle; use depends_on or separate into sub-modules |

| output references undeclared resource | Typo in resource name or resource removed | Verify resource names in main.tf match output references exactly |

| module source not found | Incorrect module path or registry reference | Verify the source path is relative (e.g., ./modules/vpc) or a valid registry address |

Examples

Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.