borghei/Claude-Skills / engineering/terraform-patterns
terraform-patterns
VerifiedTerraform module design and review: complexity and documentation analysis plus an AWS-focused misconfiguration scan. Use when writing or reviewing Terraform modules or gating IaC changes.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.3 KB |
| examples/main.tf | other | 4.4 KB |
| references/terraform-patterns.md | markdown | 3.7 KB |
| scripts/tf_module_analyzer.py | script | 13.8 KB |
| scripts/tf_security_scanner.py | script | 17.1 KB |
references/terraform-patterns.md
View on GitHub# Terraform Patterns Reference
## Module Design Patterns
### Composition Pattern
Build infrastructure from small, focused modules that do one thing well.
```hcl
module "vpc" {
source = "./modules/vpc"
cidr = "10.0.0.0/16"
}
module "database" {
source = "./modules/rds"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
}
```
### Facade Pattern
Wrap complex multi-module setups behind a simplified interface.
```hcl
module "application_stack" {
source = "./modules/app-stack"
app_name = "myapp"
environment = "production"
# Internally creates VPC, ECS, ALB, RDS, etc.
}
```
## File Organization
### Standard Module Layout
```
modules/service-name/
main.tf - Primary resources
variables.tf - Input variables (all with type + description)
outputs.tf - Module outputs (all with description)
versions.tf - terraform { required_providers {} }
locals.tf - Computed local values
data.tf - Data sources (optional)
```
### Environment Layout
```
environments/
production/
main.tf - Module calls with prod values
backend.tf - Remote state config
terraform.tfvars
staging/
main.tf
backend.tf
terraform.tfvars
```
## Security Best Practices
### S3 Bucket Security
```hcl
resource "aws_s3_bucket" "data" {
bucket = "my-secure-bucket"
}
resource "aws_s3_bucket_public_access_block" "data" {
bucket = aws_s3_bucket.data.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "data" {
bucket = aws_s3_bucket.data.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}
```
### Security Group Rules
```hcl
# Good: specific CIDR
resource "aws_security_group_rule" "ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"] # Internal only
security_group_id = aws_security_group.main.id
}
# Bad: open to world
resource "aws_security_group_rule" "ssh_bad" {
cidr_blocks = ["0.0.0.0/0"] # Never do this for SSH
}
```
### IAM Least Privilege
```hcl
data "aws_iam_policy_document" "app" {
statement {
effect = "Allow"
actions = [
"s3:GetObject",
"s3:PutObject",
]
resources = [
"${aws_s3_bucket.app.arn}/*",
]
}
}
```
## State Management
### Remote State Configuration
```hcl
terraform {
backend "s3" {
bucket = "terraform-state-myorg"
key = "production/vpc/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
```
### State Locking
Always use DynamoDB (or equivalent) for state locking to prevent concurrent modifications.
## Naming Conventions
| Resource | Convention | Example |
|----------|-----------|---------|
| Resources | snake_case, descriptive | `aws_s3_bucket.app_data` |
| Variables | snake_case, prefixed | `var.vpc_cidr` |
| Outputs | snake_case, descriptive | `output.vpc_id` |
| Modules | kebab-case directories | `modules/app-cluster/` |
| Files | lowercase, descriptive | `main.tf`, `variables.tf` |
## Provider Version Pinning
```hcl
terraform {
required_version = "~> 1.9" # the minor line you test with
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0" # the provider major you tested; read its upgrade guide before bumping
}
}
}
```
Replace the numbers with the versions you actually run (`terraform version`,
`terraform providers`), and commit `.terraform.lock.hcl` so every run resolves the same builds.
Always pin at least the minor version to prevent breaking changes.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |