Skills · Infrastructure & ops

Terraform Module Library

Unverified31/40

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.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add terraform-module-library

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

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.

The whole source

No sign-in, no blur, nothing truncated
terraform-module-library/SKILL.md252 lines5.5 KBRawView on GitHub
Frontmatter — 2 properties
nameterraform-module-library
descriptionBuild 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.
1---
2name: terraform-module-library
3description: 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.
4---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# Terraform Module Library
7 
8Production-ready Terraform module patterns for AWS, Azure, GCP, and OCI infrastructure.
9 
10## Purpose
11 
12Create reusable, well-tested Terraform modules for common cloud infrastructure patterns across multiple cloud providers.
13 
14## When to Use
15 
16- Build reusable infrastructure components
17- Standardize cloud resource provisioning
18- Implement infrastructure as code best practices
19- Create multi-cloud compatible modules
20- Establish organizational Terraform standards
21 
22## Module Structure
23 
24```
25terraform-modules/
26├── aws/
27│ ├── vpc/
28│ ├── eks/
29│ ├── rds/
30│ └── s3/
31├── azure/
32│ ├── vnet/
33│ ├── aks/
34│ └── storage/
35├── gcp/
36│ ├── vpc/
37│ ├── gke/
38│ └── cloud-sql/
39└── oci/
40 ├── vcn/
41 ├── oke/
42 └── object-storage/
43```
44 
45## Standard Module Pattern
46 
47```
48module-name/
49├── main.tf # Main resources
50├── variables.tf # Input variables
51├── outputs.tf # Output values
52├── versions.tf # Provider versions
53├── README.md # Documentation
54├── examples/ # Usage examples
55│ └── complete/
56│ ├── main.tf
57│ └── variables.tf
58└── tests/ # Terratest files
59 └── module_test.go
60```
61 
62## AWS VPC Module Example
63 
64**main.tf:**
65 
66```hcl
67resource "aws_vpc" "main" {
68 cidr_block = var.cidr_block
69 enable_dns_hostnames = var.enable_dns_hostnames
70 enable_dns_support = var.enable_dns_support
71 
72 tags = merge(
73 {
74 Name = var.name
75 },
76 var.tags
77 )
78}
79 
80resource "aws_subnet" "private" {
81 count = length(var.private_subnet_cidrs)
82 vpc_id = aws_vpc.main.id
83 cidr_block = var.private_subnet_cidrs[count.index]
84 availability_zone = var.availability_zones[count.index]
85 
86 tags = merge(
87 {
88 Name = "${var.name}-private-${count.index + 1}"
89 Tier = "private"
90 },
91 var.tags
92 )
93}
94 
95resource "aws_internet_gateway" "main" {
96 count = var.create_internet_gateway ? 1 : 0
97 vpc_id = aws_vpc.main.id
98 
99 tags = merge(
100 {
101 Name = "${var.name}-igw"
102 },
103 var.tags
104 )
105}
106```
107 
108**variables.tf:**
109 
110```hcl
111variable "name" {
112 description = "Name of the VPC"
113 type = string
114}
115 
116variable "cidr_block" {
117 description = "CIDR block for VPC"
118 type = string
119 validation {
120 condition = can(regex("^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$", var.cidr_block))
121 error_message = "CIDR block must be valid IPv4 CIDR notation."
122 }
123}
124 
125variable "availability_zones" {
126 description = "List of availability zones"
127 type = list(string)
128}
129 
130variable "private_subnet_cidrs" {
131 description = "CIDR blocks for private subnets"
132 type = list(string)
133 default = []
134}
135 
136variable "enable_dns_hostnames" {
137 description = "Enable DNS hostnames in VPC"
138 type = bool
139 default = true
140}
141 
142variable "tags" {
143 description = "Additional tags"
144 type = map(string)
145 default = {}
146}
147```
148 
149**outputs.tf:**
150 
151```hcl
152output "vpc_id" {
153 description = "ID of the VPC"
154 value = aws_vpc.main.id
155}
156 
157output "private_subnet_ids" {
158 description = "IDs of private subnets"
159 value = aws_subnet.private[*].id
160}
161 
162output "vpc_cidr_block" {
163 description = "CIDR block of VPC"
164 value = aws_vpc.main.cidr_block
165}
166```
167 
168## Best Practices
169 
1701. **Use semantic versioning** for modules
1712. **Document all variables** with descriptions
1723. **Provide examples** in examples/ directory
1734. **Use validation blocks** for input validation
1745. **Output important attributes** for module composition
1756. **Pin provider versions** in versions.tf
1767. **Use locals** for computed values
1778. **Implement conditional resources** with count/for_each
1789. **Test modules** with Terratest
17910. **Tag all resources** consistently
180 
181**Reference:** See `references/aws-modules.md` and `references/oci-modules.md`
182 
183## Module Composition
184 
185```hcl
186module "vpc" {
187 source = "../../modules/aws/vpc"
188 
189 name = "production"
190 cidr_block = "10.0.0.0/16"
191 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
192 
193 private_subnet_cidrs = [
194 "10.0.1.0/24",
195 "10.0.2.0/24",
196 "10.0.3.0/24"
197 ]
198 
199 tags = {
200 Environment = "production"
201 ManagedBy = "terraform"
202 }
203}
204 
205module "rds" {
206 source = "../../modules/aws/rds"
207 
208 identifier = "production-db"
209 engine = "postgres"
210 engine_version = "15.3"
211 instance_class = "db.t3.large"
212 
213 vpc_id = module.vpc.vpc_id
214 subnet_ids = module.vpc.private_subnet_ids
215 
216 tags = {
217 Environment = "production"
218 }
219}
220```
221 
222 
223## Testing
224 
225```go
226// tests/vpc_test.go
227package test
228 
229import (
230 "testing"
231 "github.com/gruntwork-io/terratest/modules/terraform"
232 "github.com/stretchr/testify/assert"
233)
234 
235func TestVPCModule(t *testing.T) {
236 terraformOptions := &terraform.Options{
237 TerraformDir: "../examples/complete",
238 }
239 
240 defer terraform.Destroy(t, terraformOptions)
241 terraform.InitAndApply(t, terraformOptions)
242 
243 vpcID := terraform.Output(t, terraformOptions, "vpc_id")
244 assert.NotEmpty(t, vpcID)
245}
246```
247 
248## Related Skills
249 
250- `multi-cloud-architecture` - For architectural decisions
251- `cost-optimization` - For cost-effective designs
252 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Infrastructure & ops