by skunxicat
Terraform Modules Best Practices for Production Systems
The Pattern We Found
Every cloudless foundation needs the same building blocks:
- Foundation (
cloudless-infra) - labeling, environment, consistency - Compute (
terraform-aws-lambda-runtime) - ECR + SSM for custom runtimes - Interface (
terraform-aws-rest-apiorterraform-aws-website) - how users reach your system
Terraform Module Design Principles
Single Responsibility Principle: Each terraform module does one thing perfectly
terraform-aws-website= CloudFront + S3 + SSL + Route53 from FQDNterraform-aws-lambda-runtime= ECR + SSM for runtime sharingterraform-aws-rest-api= API Gateway + keys + usage plans
Infrastructure as Code Best Practices:
- CloudPosse Compatible: All modules use
context.tffor consistent labeling - Git Sourceable: Direct GitHub references for version control
- Minimal Interface: Expose only what users need, abstract the complexity
module "website" {
source = "git::https://github.com/ql4b/terraform-aws-website.git"
fqdn = "example.com"
context = module.label.context
}
The Abstraction Strategy
We’re not reinventing AWS services. We’re wrapping complexity with sensible defaults:
terraform-aws-websitewraps CloudPosse’scloudfront-s3-cdn+ ACM + Route53terraform-aws-lambda-runtimewraps CloudPosse’secr+ SSM parametersterraform-aws-rest-apiwraps raw API Gateway resources
Why This Works
Composability: Mix and match modules as needed
Upgradability: Replace modules when you outgrow them
Transparency: Every resource is explicit in the module code
Reusability: Same patterns across all cloudless foundations
Module Naming Convention
terraform-aws-{purpose}
terraform-aws-website- complete website infrastructureterraform-aws-lambda-runtime- custom runtime supportterraform-aws-rest-api- API Gateway setup
The Network Effect
Each module makes the others more valuable:
cloudless-apiuseslambda-runtime+rest-apicloudless-webuseswebsite- Future foundations can mix and match
Repository Strategy
Each module is its own repo for:
- Independent versioning
- Clear ownership
- Focused documentation
- Git source references
What’s Next
terraform-aws-database- RDS + connection poolingterraform-aws-queue- SQS + DLQ setupterraform-aws-storage- S3 + lifecycle policiesterraform-aws-monitoring- CloudWatch + alarms
The goal: Every common AWS pattern becomes a 5-line module call.