Terraform Module Library

Build production-ready Terraform modules for AWS, Azure & GCP infrastructure

✨ The solution you've been looking for

Verified
Tested and verified by our team
25450 Stars

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.

terraform infrastructure-as-code aws azure gcp multi-cloud devops modules
Repository

See It In Action

Interactive preview & real-world examples

Live Demo
Skill Demo Animation

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

1

Install

claude-code skill install terraform-module-library

claude-code skill install terraform-module-library
2

Config

3

First Trigger

@terraform-module-library help

Commands

CommandDescriptionRequired Args
@terraform-module-library create-standardized-vpc-moduleBuild a reusable VPC module with subnets, gateways, and proper tagging for consistent network infrastructure across environmentsNone
@terraform-module-library multi-cloud-module-libraryEstablish a module library structure supporting AWS, Azure, and GCP with consistent patterns and testingNone
@terraform-module-library module-composition-architectureCompose multiple modules together to create complete infrastructure stacks while maintaining modularityNone

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

  1. Use semantic versioning for modules
  2. Document all variables with descriptions
  3. Provide examples in examples/ directory
  4. Use validation blocks for input validation
  5. Output important attributes for module composition
  6. Pin provider versions in versions.tf
  7. Use locals for computed values
  8. Implement conditional resources with count/for_each
  9. Test modules with Terratest
  10. 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 example
  • assets/rds-module/ - RDS module example
  • references/aws-modules.md - AWS module patterns
  • references/azure-modules.md - Azure module patterns
  • references/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}
  • multi-cloud-architecture - For architectural decisions
  • cost-optimization - For cost-effective designs

What Users Are Saying

Real feedback from the community

Environment Matrix

Dependencies

Terraform 1.0+
Cloud provider CLI tools (aws-cli, azure-cli, gcloud)

Framework Support

Terratest ✓ (recommended) AWS Provider ✓ Azure Provider ✓ Google Cloud Provider ✓

Context Window

Token Usage ~3K-8K tokens for complex multi-module compositions

Security & Privacy

Information

Author
wshobson
Updated
2026-01-30
Category
productivity-tools