Terraform Module Library
Build production-ready Terraform modules for AWS, Azure & GCP infrastructure
✨ The solution you've been looking for
Build reusable Terraform modules for AWS, Azure, and GCP infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.
See It In Action
Interactive preview & real-world examples
AI Conversation Simulator
See how users interact with this skill
User Prompt
Help me create a Terraform VPC module for AWS that includes private subnets, internet gateway, and follows best practices for tagging and validation
Skill Processing
Analyzing request...
Agent Response
Complete VPC module with main.tf, variables.tf, outputs.tf, proper validation, and usage examples
Quick Start (3 Steps)
Get up and running in minutes
Install
claude-code skill install terraform-module-library
claude-code skill install terraform-module-libraryConfig
First Trigger
@terraform-module-library helpCommands
| Command | Description | Required Args |
|---|---|---|
| @terraform-module-library create-standardized-vpc-module | Build a reusable VPC module with subnets, gateways, and proper tagging for consistent network infrastructure across environments | None |
| @terraform-module-library multi-cloud-module-library | Establish a module library structure supporting AWS, Azure, and GCP with consistent patterns and testing | None |
| @terraform-module-library module-composition-architecture | Compose multiple modules together to create complete infrastructure stacks while maintaining modularity | None |
Typical Use Cases
Create Standardized VPC Module
Build a reusable VPC module with subnets, gateways, and proper tagging for consistent network infrastructure across environments
Multi-Cloud Module Library
Establish a module library structure supporting AWS, Azure, and GCP with consistent patterns and testing
Module Composition Architecture
Compose multiple modules together to create complete infrastructure stacks while maintaining modularity
Overview
Terraform Module Library
Production-ready Terraform module patterns for AWS, Azure, and GCP infrastructure.
Purpose
Create reusable, well-tested Terraform modules for common cloud infrastructure patterns across multiple cloud providers.
When to Use
- Build reusable infrastructure components
- Standardize cloud resource provisioning
- Implement infrastructure as code best practices
- Create multi-cloud compatible modules
- Establish organizational Terraform standards
Module Structure
terraform-modules/
├── aws/
│ ├── vpc/
│ ├── eks/
│ ├── rds/
│ └── s3/
├── azure/
│ ├── vnet/
│ ├── aks/
│ └── storage/
└── gcp/
├── vpc/
├── gke/
└── cloud-sql/
Standard Module Pattern
module-name/
├── main.tf # Main resources
├── variables.tf # Input variables
├── outputs.tf # Output values
├── versions.tf # Provider versions
├── README.md # Documentation
├── examples/ # Usage examples
│ └── complete/
│ ├── main.tf
│ └── variables.tf
└── tests/ # Terratest files
└── module_test.go
AWS VPC Module Example
main.tf:
1resource "aws_vpc" "main" {
2 cidr_block = var.cidr_block
3 enable_dns_hostnames = var.enable_dns_hostnames
4 enable_dns_support = var.enable_dns_support
5
6 tags = merge(
7 {
8 Name = var.name
9 },
10 var.tags
11 )
12}
13
14resource "aws_subnet" "private" {
15 count = length(var.private_subnet_cidrs)
16 vpc_id = aws_vpc.main.id
17 cidr_block = var.private_subnet_cidrs[count.index]
18 availability_zone = var.availability_zones[count.index]
19
20 tags = merge(
21 {
22 Name = "${var.name}-private-${count.index + 1}"
23 Tier = "private"
24 },
25 var.tags
26 )
27}
28
29resource "aws_internet_gateway" "main" {
30 count = var.create_internet_gateway ? 1 : 0
31 vpc_id = aws_vpc.main.id
32
33 tags = merge(
34 {
35 Name = "${var.name}-igw"
36 },
37 var.tags
38 )
39}
variables.tf:
1variable "name" {
2 description = "Name of the VPC"
3 type = string
4}
5
6variable "cidr_block" {
7 description = "CIDR block for VPC"
8 type = string
9 validation {
10 condition = can(regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$", var.cidr_block))
11 error_message = "CIDR block must be valid IPv4 CIDR notation."
12 }
13}
14
15variable "availability_zones" {
16 description = "List of availability zones"
17 type = list(string)
18}
19
20variable "private_subnet_cidrs" {
21 description = "CIDR blocks for private subnets"
22 type = list(string)
23 default = []
24}
25
26variable "enable_dns_hostnames" {
27 description = "Enable DNS hostnames in VPC"
28 type = bool
29 default = true
30}
31
32variable "tags" {
33 description = "Additional tags"
34 type = map(string)
35 default = {}
36}
outputs.tf:
1output "vpc_id" {
2 description = "ID of the VPC"
3 value = aws_vpc.main.id
4}
5
6output "private_subnet_ids" {
7 description = "IDs of private subnets"
8 value = aws_subnet.private[*].id
9}
10
11output "vpc_cidr_block" {
12 description = "CIDR block of VPC"
13 value = aws_vpc.main.cidr_block
14}
Best Practices
- Use semantic versioning for modules
- Document all variables with descriptions
- Provide examples in examples/ directory
- Use validation blocks for input validation
- Output important attributes for module composition
- Pin provider versions in versions.tf
- Use locals for computed values
- Implement conditional resources with count/for_each
- Test modules with Terratest
- Tag all resources consistently
Module Composition
1module "vpc" {
2 source = "../../modules/aws/vpc"
3
4 name = "production"
5 cidr_block = "10.0.0.0/16"
6 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
7
8 private_subnet_cidrs = [
9 "10.0.1.0/24",
10 "10.0.2.0/24",
11 "10.0.3.0/24"
12 ]
13
14 tags = {
15 Environment = "production"
16 ManagedBy = "terraform"
17 }
18}
19
20module "rds" {
21 source = "../../modules/aws/rds"
22
23 identifier = "production-db"
24 engine = "postgres"
25 engine_version = "15.3"
26 instance_class = "db.t3.large"
27
28 vpc_id = module.vpc.vpc_id
29 subnet_ids = module.vpc.private_subnet_ids
30
31 tags = {
32 Environment = "production"
33 }
34}
Reference Files
assets/vpc-module/- Complete VPC module exampleassets/rds-module/- RDS module examplereferences/aws-modules.md- AWS module patternsreferences/azure-modules.md- Azure module patternsreferences/gcp-modules.md- GCP module patterns
Testing
1// tests/vpc_test.go
2package test
3
4import (
5 "testing"
6 "github.com/gruntwork-io/terratest/modules/terraform"
7 "github.com/stretchr/testify/assert"
8)
9
10func TestVPCModule(t *testing.T) {
11 terraformOptions := &terraform.Options{
12 TerraformDir: "../examples/complete",
13 }
14
15 defer terraform.Destroy(t, terraformOptions)
16 terraform.InitAndApply(t, terraformOptions)
17
18 vpcID := terraform.Output(t, terraformOptions, "vpc_id")
19 assert.NotEmpty(t, vpcID)
20}
Related Skills
multi-cloud-architecture- For architectural decisionscost-optimization- For cost-effective designs
What Users Are Saying
Real feedback from the community
Environment Matrix
Dependencies
Framework Support
Context Window
Security & Privacy
Information
- Author
- wshobson
- Updated
- 2026-01-30
- Category
- productivity-tools
Related Skills
Terraform Module Library
Build reusable Terraform modules for AWS, Azure, and GCP infrastructure following …
View Details →Prowler
Main entry point for Prowler development - quick reference for all components. Trigger: General …
View Details →Prowler
Main entry point for Prowler development - quick reference for all components. Trigger: General …
View Details →