agiza_agents
by @bizzy604
25 advanced engineering agent skills and plugins for Claude Code, Codex, Gemini CLI, Cursor, OpenClaw. Agent design, RAG, MCP servers, CI/CD, database design...
clawhub install agizaπ About This Skill
name: "terraform-patterns" description: "Terraform infrastructure-as-code agent skill and plugin for Claude Code, Codex, Gemini CLI, Cursor, OpenClaw. Covers module design patterns, state management strategies, provider configuration, security hardening, policy-as-code with Sentinel/OPA, and CI/CD plan/apply workflows. Use when: user wants to design Terraform modules, manage state backends, review Terraform security, implement multi-region deployments, or follow IaC best practices." license: MIT metadata: version: 1.0.0 author: Alireza Rezvani category: engineering updated: 2026-03-15
Terraform Patterns
> Predictable infrastructure. Secure state. Modules that compose. No drift.
Opinionated Terraform workflow that turns sprawling HCL into well-structured, secure, production-grade infrastructure code. Covers module design, state management, provider patterns, security hardening, and CI/CD integration.
Not a Terraform tutorial β a set of concrete decisions about how to write infrastructure code that doesn't break at 3 AM.
Slash Commands
| Command | What it does |
|---------|-------------|
| /terraform:review | Analyze Terraform code for anti-patterns, security issues, and structure problems |
| /terraform:module | Design or refactor a Terraform module with proper inputs, outputs, and composition |
| /terraform:security | Audit Terraform code for security vulnerabilities, secrets exposure, and IAM misconfigurations |
When This Skill Activates
Recognize these patterns from the user:
.tf files, HCL, Terraform modules, state management, provider configuration, infrastructure-as-codeIf the user has .tf files or wants to provision infrastructure with Terraform β this skill applies.
Workflow
/terraform:review β Terraform Code Review
1. Analyze current state
- Read all .tf files in the target directory
- Identify module structure (flat vs nested)
- Count resources, data sources, variables, outputs
- Check naming conventions
2. Apply review checklist
MODULE STRUCTURE
βββ Variables have descriptions and type constraints
βββ Outputs expose only what consumers need
βββ Resources use consistent naming: {provider}_{type}_{purpose}
βββ Locals used for computed values and DRY expressions
βββ No hardcoded values β everything parameterized or in locals STATE & BACKEND
βββ Remote backend configured (S3, GCS, Azure Blob, Terraform Cloud)
βββ State locking enabled (DynamoDB for S3, native for others)
βββ State encryption at rest enabled
βββ No secrets stored in state (or state access is restricted)
βββ Workspaces or directory isolation for environments
PROVIDERS
βββ Version constraints use pessimistic operator: ~> 5.0
βββ Required providers block in terraform {} block
βββ Provider aliases for multi-region or multi-account
βββ No provider configuration in child modules
SECURITY
βββ No hardcoded secrets, keys, or passwords
βββ IAM follows least-privilege principle
βββ Encryption enabled for storage, databases, secrets
βββ Security groups are not overly permissive (no 0.0.0.0/0 ingress on sensitive ports)
βββ Sensitive variables marked with sensitive = true
3. Generate report
python3 scripts/tf_module_analyzer.py ./terraform
4. Run security scan
python3 scripts/tf_security_scanner.py ./terraform
/terraform:module β Module Design
1. Identify module scope - Single responsibility: one module = one logical grouping - Determine inputs (variables), outputs, and resource boundaries - Decide: flat module (single directory) vs nested (calling child modules)
2. Apply module design checklist
STRUCTURE
βββ main.tf β Primary resources
βββ variables.tf β All input variables with descriptions and types
βββ outputs.tf β All outputs with descriptions
βββ versions.tf β terraform {} block with required_providers
βββ locals.tf β Computed values and naming conventions
βββ data.tf β Data sources (if any)
βββ README.md β Usage examples and variable documentation VARIABLES
βββ Every variable has: description, type, validation (where applicable)
βββ Sensitive values marked: sensitive = true
βββ Defaults provided for optional settings
βββ Use object types for related settings: variable "config" { type = object({...}) }
βββ Validate with: validation { condition = ... }
OUTPUTS
βββ Output IDs, ARNs, endpoints β things consumers need
βββ Include description on every output
βββ Mark sensitive outputs: sensitive = true
βββ Don't output entire resources β only specific attributes
COMPOSITION
βββ Root module calls child modules
βββ Child modules never call other child modules
βββ Pass values explicitly β no hidden data source lookups in child modules
βββ Provider configuration only in root module
βββ Use module "name" { source = "./modules/name" }
3. Generate module scaffold - Output file structure with boilerplate - Include variable validation blocks - Add lifecycle rules where appropriate
/terraform:security β Security Audit
1. Code-level audit
| Check | Severity | Fix |
|-------|----------|-----|
| Hardcoded secrets in .tf files | Critical | Use variables with sensitive = true or vault |
| IAM policy with * actions | Critical | Scope to specific actions and resources |
| Security group with 0.0.0.0/0 on port 22/3389 | Critical | Restrict to known CIDR blocks or use SSM/bastion |
| S3 bucket without encryption | High | Add server_side_encryption_configuration block |
| S3 bucket with public access | High | Add aws_s3_bucket_public_access_block |
| RDS without encryption | High | Set storage_encrypted = true |
| RDS publicly accessible | High | Set publicly_accessible = false |
| CloudTrail not enabled | Medium | Add aws_cloudtrail resource |
| Missing prevent_destroy on stateful resources | Medium | Add lifecycle { prevent_destroy = true } |
| Variables without sensitive = true for secrets | Medium | Add sensitive = true to secret variables |
2. State security audit
| Check | Severity | Fix | |-------|----------|-----| | Local state file | Critical | Migrate to remote backend with encryption | | Remote state without encryption | High | Enable encryption on backend (SSE-S3, KMS) | | No state locking | High | Enable DynamoDB for S3, native for TF Cloud | | State accessible to all team members | Medium | Restrict via IAM policies or TF Cloud teams |
3. Generate security report
python3 scripts/tf_security_scanner.py ./terraform
python3 scripts/tf_security_scanner.py ./terraform --output json
Tooling
scripts/tf_module_analyzer.py
CLI utility for analyzing Terraform directory structure and module quality.
Features:
Usage:
# Analyze a Terraform directory
python3 scripts/tf_module_analyzer.py ./terraformJSON output
python3 scripts/tf_module_analyzer.py ./terraform --output jsonAnalyze a specific module
python3 scripts/tf_module_analyzer.py ./modules/vpc
scripts/tf_security_scanner.py
CLI utility for scanning .tf files for common security issues.
Features:
Usage:
# Scan a Terraform directory
python3 scripts/tf_security_scanner.py ./terraformJSON output
python3 scripts/tf_security_scanner.py ./terraform --output jsonStrict mode (elevate warnings)
python3 scripts/tf_security_scanner.py ./terraform --strict
Module Design Patterns
Pattern 1: Flat Module (Small/Medium Projects)
infrastructure/
βββ main.tf # All resources
βββ variables.tf # All inputs
βββ outputs.tf # All outputs
βββ versions.tf # Provider requirements
βββ terraform.tfvars # Environment values (not committed)
βββ backend.tf # Remote state configuration
Best for: Single application, < 20 resources, one team owns everything.
Pattern 2: Nested Modules (Medium/Large Projects)
infrastructure/
βββ environments/
β βββ dev/
β β βββ main.tf # Calls modules with dev params
β β βββ backend.tf # Dev state backend
β β βββ terraform.tfvars
β βββ staging/
β β βββ ...
β βββ prod/
β βββ ...
βββ modules/
β βββ networking/
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β βββ compute/
β β βββ ...
β βββ database/
β βββ ...
βββ versions.tf
Best for: Multiple environments, shared infrastructure patterns, team collaboration.
Pattern 3: Mono-Repo with Terragrunt
infrastructure/
βββ terragrunt.hcl # Root config
βββ modules/ # Reusable modules
β βββ vpc/
β βββ eks/
β βββ rds/
βββ dev/
β βββ terragrunt.hcl # Dev overrides
β βββ vpc/
β β βββ terragrunt.hcl # Module invocation
β βββ eks/
β βββ terragrunt.hcl
βββ prod/
βββ terragrunt.hcl
βββ ...
Best for: Large-scale, many environments, DRY configuration, team-level isolation.
Provider Configuration Patterns
Version Pinning
terraform {
required_version = ">= 1.5.0" required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0" # Allow 5.x, block 6.0
}
random = {
source = "hashicorp/random"
version = "~> 3.5"
}
}
}
Multi-Region with Aliases
provider "aws" {
region = "us-east-1"
}provider "aws" {
alias = "west"
region = "us-west-2"
}
resource "aws_s3_bucket" "primary" {
bucket = "my-app-primary"
}
resource "aws_s3_bucket" "replica" {
provider = aws.west
bucket = "my-app-replica"
}
Multi-Account with Assume Role
provider "aws" {
alias = "production"
region = "us-east-1" assume_role {
role_arn = "arn:aws:iam::PROD_ACCOUNT_ID:role/TerraformRole"
}
}
State Management Decision Tree
Single developer, small project?
βββ Yes β Local state (but migrate to remote ASAP)
βββ No
βββ Using Terraform Cloud/Enterprise?
β βββ Yes β TF Cloud native backend (built-in locking, encryption, RBAC)
βββ No
βββ AWS?
β βββ S3 + DynamoDB (encryption, locking, versioning)
βββ GCP?
β βββ GCS bucket (native locking, encryption)
βββ Azure?
β βββ Azure Blob Storage (native locking, encryption)
βββ Other?
βββ Consul or PostgreSQL backendEnvironment isolation strategy:
βββ Separate state files per environment (recommended)
β βββ Option A: Separate directories (dev/, staging/, prod/)
β βββ Option B: Terraform workspaces (simpler but less isolation)
βββ Single state file for all environments (never do this)
CI/CD Integration Patterns
GitHub Actions Plan/Apply
# .github/workflows/terraform.yml
name: Terraform
on:
pull_request:
paths: ['terraform/**']
push:
branches: [main]
paths: ['terraform/**']jobs:
plan:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- run: terraform validate
- run: terraform plan -out=tfplan
- run: terraform show -json tfplan > plan.json
# Post plan as PR comment
apply:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment: production
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- run: terraform apply -auto-approve
Drift Detection
# Run on schedule to detect drift
name: Drift Detection
on:
schedule:
- cron: '0 6 * * 1-5' # Weekdays at 6 AMjobs:
detect:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- run: |
terraform plan -detailed-exitcode -out=drift.tfplan 2>&1 | tee drift.log
EXIT_CODE=$?
if [ $EXIT_CODE -eq 2 ]; then
echo "DRIFT DETECTED β review drift.log"
# Send alert (Slack, PagerDuty, etc.)
fi
Proactive Triggers
Flag these without being asked:
version = "~> X.0" to prevent breaking upgrades.sensitive = true, or integrate Vault/SSM."Action": "*" β Scope to specific actions. No wildcard actions in production.prevent_destroy on databases/storage β Add lifecycle block to prevent accidental deletion.Installation
One-liner (any tool)
git clone https://github.com/alirezarezvani/claude-skills.git
cp -r claude-skills/engineering/terraform-patterns ~/.claude/skills/
Multi-tool install
./scripts/convert.sh --skill terraform-patterns --tool codex|gemini|cursor|windsurf|openclaw
OpenClaw
clawhub install terraform-patterns