agentleFS
aiFabricoComaiFabricoCom/fabrico-collections/.claude/skills/fabrico-implementing-terraform-modules/SKILL.md

fabrico-implementing-terraform-modules

Skill2 starsChanged 4 months agoMITView on GitHub

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.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 5 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create reusable, well-tested Terraform modules for common cloud infrastructure patterns across multiple cloud providers.

    line 12
  2. Distinctive:

    Create multi-cloud compatible modules

    line 19
  3. Distinctive:

    Use Terratest (Go) to test Terraform modules.

    line 197
  4. Very specific:

    Always wrap options with terraform.WithDefaultRetryableErrors

    line 204
  5. Very specific:

    Always use runtime.Caller(0) to resolve examples/complete/ path relative to the test file — never use hardcoded relative paths

    line 205
  6. Very specific:

    Always use single_nat_gateway = true (or equivalent cost-reducing flags) in test examples

    line 206
  7. Distinctive:

    Use a dedicated AWS test account — never run against production

    line 208
  8. Distinctive:

    Use plain Terraform when:

    line 213

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

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(cidrnetmask(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 "enable_dns_support" {
  description = "Enable DNS support in VPC"
  type        = bool
  default     = true
}

variable "create_internet_gateway" {
  description = "Whether to create an Internet Gateway"
  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. Pin provider versions in versions.tf — use aws ~> 6.0, azurerm ~> 4.0, google ~> 5.0
  3. Document all variables with descriptions
  4. Provide examples in examples/ directory
  5. Use validation blocks for input validation
  6. Output important attributes for module composition
  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 Files

  • references/aws-modules.md - AWS module patterns
  • references/azure-modules.md - Azure module patterns
  • references/gcp-modules.md - GCP module patterns

Testing

Use Terratest (Go) to test Terraform modules. Every module must include:

  • examples/complete/ — a root module that calls the module under test with realistic values and re-exports its outputs
  • tests/module_test.go — Go test file that runs InitAndApply, reads outputs, asserts expected values, and always defers Destroy

Apply the following rules when writing tests:

  • Always call t.Parallel()
  • Always wrap options with terraform.WithDefaultRetryableErrors
  • Always use runtime.Caller(0) to resolve examples/complete/ path relative to the test file — never use hardcoded relative paths
  • Always use single_nat_gateway = true (or equivalent cost-reducing flags) in test examples
  • Provide a plan-only variant of each test (using InitAndPlanAndShowWithStruct) for fast PR validation that requires no AWS credentials
  • Use a dedicated AWS test account — never run against production
  • Set -timeout 30m in CI to avoid hanging runs

Terraform vs Terragrunt Decision

Use plain Terraform when:

  • Single environment, single region
  • 2–3 environments in the same region (use workspaces or directory layout)
  • Existing project without Terragrunt (don't migrate mid-project)

Use Terragrunt when:

  • 4+ environments or multi-region deployments
  • Monorepo with many independent stacks (need run-all, dependency orchestration)
  • Team needs strict environment parity via inheritance
  • Multi-account AWS (landing zone pattern)
  • Greenfield with expected growth

Terragrunt Golden Path structure:

infrastructure/
├── terragrunt.hcl              # Root config (remote_state, generate provider)
├── _envcommon/                  # Shared module references
│   ├── vpc.hcl
│   ├── eks.hcl
│   └── rds.hcl
├── dev/
│   ├── env.hcl                 # Environment-level vars
│   ├── vpc/terragrunt.hcl
│   └── eks/terragrunt.hcl
├── staging/
│   └── ...
└── prod/
    └── ...

Related Skills

  • fabrico-designing-multi-cloud-architecture - For architectural decisions
  • fabrico-optimizing-cloud-cost - For cost-effective designs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.