Skip to content
Skillpedia
Deploy & cloud (DevOps)41k Β· #6664

terraform-module-library

What it does

This tool helps create reusable code blocks (called modules) to set up cloud infrastructure (like servers, networks) in a standardized and efficient way. It follows best practices to ensure your modules work well and can be used across different cloud providers.

When to use it

  • βœ“When building infrastructure components you'll use multiple times.
  • βœ“To ensure your cloud setup is always consistent.
  • βœ“When you want to use code to manage your infrastructure in an organized manner.

Skill link

https://github.com/wshobson/agents/blob/main/plugins/cloud-infrastructure/skills/terraform-module-library/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/wshobson/agents/blob/main/plugins/cloud-infrastructure/skills/terraform-module-library/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œCreate a Terraform module to set up a virtual network in AWS.”

5 new skills a week. 1 minute to read.

How it works

The tool provides templates and code examples you can adapt. It organizes these modules in a structured way, with files for defining resources, input variables, outputs, and documentation, making them easy to reuse and maintain.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Terraform Module Library

Production-ready Terraform module patterns for AWS, Azure, GCP, and OCI 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/
└── oci/
    β”œβ”€β”€ vcn/
    β”œβ”€β”€ oke/
    └── object-storage/

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:

resource "aws_vpc" "main" {
  cidr_block           = var.cidr_block
  enable_dns_hostnames = var.enable_dns_hostnames
  enable_dns_support   = var.enable_dns_support

  tags = merge(
    {
      Name = var.name
    },
    var.tags
  )
}

resource "aws_subnet" "private" {
  count             = length(var.private_subnet_cidrs)
  vpc_id            = aws_vpc.main.id
  cidr_block        = var.private_subnet_cidrs[count.index]
  availability_zone = var.availability_zones[count.index]

  tags = merge(
    {
      Name = "${var.name}-private-${count.index + 1}"
      Tier = "private"
    },
    var.tags
  )
}

resource "aws_internet_gateway" "main" {
  count  = var.create_internet_gateway ? 1 : 0
  vpc_id = aws_vpc.main.id

  tags = merge(
    {
      Name = "${var.name}-igw"
    },
    var.tags
  )
}

variables.tf:

variable "name" {
  description = "Name of the VPC"
  type        = string
}

variable "cidr_block" {
  description = "CIDR block for VPC"
  type        = string
  validation {
    condition     = can(regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$", var.cidr_block))
    error_message = "CIDR block must be valid IPv4 CIDR notation."
  }
}

variable "availability_zones" {
  description = "List of availability zones"
  type        = list(string)
}

variable "private_subnet_cidrs" {
  description = "CIDR blocks for private subnets"
  type        = list(string)
  default     = []
}

variable "enable_dns_hostnames" {
  description = "Enable DNS hostnames in VPC"
  type        = bool
  default     = true
}

variable "tags" {
  description = "Additional tags"
  type        = map(string)
  default     = {}
}

outputs.tf:

output "vpc_id" {
  description = "ID of the VPC"
  value       = aws_vpc.main.id
}

output "private_subnet_ids" {
  description = "IDs of private subnets"
  value       = aws_subnet.private[*].id
}

output "vpc_cidr_block" {
  description = "CIDR block of VPC"
  value       = aws_vpc.main.cidr_block
}

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

Reference: See references/aws-modules.md and references/oci-modules.md

Module Composition

module "vpc" {
  source = "../../modules/aws/vpc"

  name               = "production"
  cidr_block         = "10.0.0.0/16"
  availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]

  private_subnet_cidrs = [
    "10.0.1.0/24",
    "10.0.2.0/24",
    "10.0.3.0/24"
  ]

  tags = {
    Environment = "production"
    ManagedBy   = "terraform"
  }
}

module "rds" {
  source = "../../modules/aws/rds"

  identifier     = "production-db"
  engine         = "postgres"
  engine_version = "15.3"
  instance_class = "db.t3.large"

  vpc_id     = module.vpc.vpc_id
  subnet_ids = module.vpc.private_subnet_ids

  tags = {
    Environment = "production"
  }
}

Testing


…
FAQ

What is a Terraform module?

It's a collection of Terraform files that form a logical unit of infrastructure, like a network or a database, which can be reused across different projects.

Which cloud providers are supported?

AWS, Azure, GCP, and OCI (Oracle Cloud Infrastructure).

What are 'best practices' in this context?

These are recommendations for writing high-quality infrastructure code, such as documenting everything, validating inputs, and testing the code.

Details

Original description by the author

Build reusable Terraform modules for AWS, Azure, GCP, and OCI infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.

repo: wshobson/agents

Popularity

GitHub stars
41k
Ranking position
#6664
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills