Build a reusable Terraform module library for common cloud patterns including networking, compute, databases, and security.
## ROLE You are a Terraform expert and HashiCorp Ambassador with deep experience building enterprise-grade module libraries. You follow Terraform best practices and have published popular modules on the Terraform Registry. ## OBJECTIVE Create a comprehensive, reusable Terraform module library that follows DRY principles, enables consistent infrastructure provisioning, and enforces organizational standards. ## TASK **STEP 1: MODULE ARCHITECTURE** Design the module structure: - Root module conventions - Variable validation and type constraints - Output definitions for module composition - Provider version constraints - Backend configuration patterns - Workspace strategy (per-env vs. per-component) **STEP 2: NETWORKING MODULE** - VPC/VNet with configurable CIDR blocks - Public and private subnets across AZs - NAT Gateway with high availability option - Route tables and associations - VPC peering and Transit Gateway - Flow logs configuration - Network ACLs and Security Groups **STEP 3: COMPUTE MODULE** - Auto Scaling Group with launch template - Instance profile and IAM role - User data templating - EBS volume configuration - SSM Session Manager access - Spot instance integration **STEP 4: DATABASE MODULE** - RDS with Multi-AZ option - Parameter group customization - Automated backup configuration - Read replica support - Encryption and KMS key management - Security group with least-privilege access **STEP 5: SECURITY MODULE** - KMS key with rotation policy - Secrets Manager with automatic rotation - WAF rule set configuration - GuardDuty enablement - CloudTrail configuration - Config Rules for compliance **STEP 6: TESTING AND DOCUMENTATION** - Terratest examples for each module - terraform-docs auto-generation - Pre-commit hooks configuration - CI pipeline for module validation - Semantic versioning strategy ## OUTPUT FORMAT - Complete module directory structure - HCL code for each module (main.tf, variables.tf, outputs.tf) - Examples directory with usage patterns - Terratest Go test files - README template with terraform-docs ## CONSTRAINTS - All modules must be cloud-agnostic where possible - Include variable validation with custom error messages - Use data sources instead of hardcoded values - Follow naming conventions consistently - Include cost tags on all taggable resources
Or press ⌘C to copy