Overview
Builds well-structured, reusable Terraform modules following best practices: main.tf, variables.tf (with validation), outputs.tf, versions.tf, remote state backend configuration, and a complete example module for a common pattern (VPC + EC2 + S3 bucket, or equivalent on other clouds).
When to Use This Skill
- Provisioning or refactoring cloud infrastructure as code.
- Creating reusable components that multiple teams or projects will use.
- The user says "Terraform", "IaC", "provision AWS", "create VPC", etc.
Prerequisites
- Terraform >= 1.5 installed.
- Cloud provider credentials configured (AWS profile, GCP application default, Azure CLI).
- Remote state backend (S3 + DynamoDB for AWS, GCS for GCP, etc.).
Steps
Module structure:
modules/vpc/
main.tf
variables.tf
outputs.tf
versions.tf
variables.tf:
- Descriptive descriptions.
type constraints.
default where safe.
validation blocks for important vars.
main.tf:
- Resources with consistent naming (use
local.name or var.name prefix).
- Data sources.
- Locals for computed values.
outputs.tf:
- Only expose what consumers need.
- Sensitive outputs marked.
State & backend:
- Recommend remote backend from day one.
- Provide
backend.tf example (commented for module, required in root).
Complete example:
- A full root module that uses the VPC module + creates an EC2 instance + S3 bucket with proper IAM.
Output:
- All module files.
- Example usage in a root
main.tf.
terraform init/plan/apply commands.
- State migration notes.
Examples
A complete, reusable vpc module for AWS (with public/private subnets, NAT, route tables, security groups) plus a root example that provisions a small web server behind it and an S3 bucket is included.
Edge Cases & Error Handling
- Existing resources: Use
terraform import guidance.
- Multi-region / multi-account: Show workspace or provider alias patterns.
- Drift detection: Regular
terraform plan in CI.
Verification
terraform init.
terraform plan — clean plan.
terraform apply — resources created.
terraform destroy — cleans up.
- Module can be called from another repo with
source = "git::..." or Terraform Registry.
- Success: Infrastructure is reproducible, state is remote and locked, variables are validated, and the module is easy to reuse.
References
Source: Nikoxkx/Agent-Skills — distributed by TomeVault.
1---2name: terraform-module-builder3description: Creates reusable Terraform modules for cloud infrastructure. Use when provisioning AWS, GCP, or Azure resources with Infrastructure as Code.4license: Apache-2.05---67## Overview89Builds well-structured, reusable Terraform modules following best practices: `main.tf`, `variables.tf` (with validation), `outputs.tf`, `versions.tf`, remote state backend configuration, and a complete example module for a common pattern (VPC + EC2 + S3 bucket, or equivalent on other clouds).1011## When to Use This Skill1213- Provisioning or refactoring cloud infrastructure as code.14- Creating reusable components that multiple teams or projects will use.15- The user says "Terraform", "IaC", "provision AWS", "create VPC", etc.1617## Prerequisites1819- Terraform >= 1.5 installed.20- Cloud provider credentials configured (AWS profile, GCP application default, Azure CLI).21- Remote state backend (S3 + DynamoDB for AWS, GCS for GCP, etc.).2223## Steps24251. **Module structure**:26 ```27 modules/vpc/28 main.tf29 variables.tf30 outputs.tf31 versions.tf32 ```33342. **variables.tf**:35 - Descriptive descriptions.36 - `type` constraints.37 - `default` where safe.38 - `validation` blocks for important vars.39403. **main.tf**:41 - Resources with consistent naming (use `local.name` or `var.name` prefix).42 - Data sources.43 - Locals for computed values.44454. **outputs.tf**:46 - Only expose what consumers need.47 - Sensitive outputs marked.48495. **State & backend**:50 - Recommend remote backend from day one.51 - Provide `backend.tf` example (commented for module, required in root).52536. **Complete example**:54 - A full root module that uses the VPC module + creates an EC2 instance + S3 bucket with proper IAM.55567. **Output**:57 - All module files.58 - Example usage in a root `main.tf`.59 - `terraform init/plan/apply` commands.60 - State migration notes.6162## Examples6364A complete, reusable `vpc` module for AWS (with public/private subnets, NAT, route tables, security groups) plus a root example that provisions a small web server behind it and an S3 bucket is included.6566## Edge Cases & Error Handling6768- **Existing resources**: Use `terraform import` guidance.69- **Multi-region / multi-account**: Show workspace or provider alias patterns.70- **Drift detection**: Regular `terraform plan` in CI.7172## Verification73741. `terraform init`.752. `terraform plan` — clean plan.763. `terraform apply` — resources created.774. `terraform destroy` — cleans up.785. Module can be called from another repo with `source = "git::..."` or Terraform Registry.796. Success: Infrastructure is reproducible, state is remote and locked, variables are validated, and the module is easy to reuse.8081## References8283- [Terraform Documentation](https://developer.hashicorp.com/terraform/docs)84- [Terraform Module Best Practices](https://developer.hashicorp.com/terraform/language/modules/develop)85- [AWS Provider](https://registry.terraform.io/providers/hashicorp/aws/latest)8687---88> Source: [Nikoxkx/Agent-Skills](https://github.com/Nikoxkx/Agent-Skills) — distributed by [TomeVault](https://tomevault.io).89<!-- tomevault:4.0:skill_md:2026-06-15 -->