| name | module-design-checklist |
| description | Pre-publish checklist and design guide for Terraform/OpenTofu modules — covers interface design, input validation, output documentation, for_each patterns, version pinning, and testability. |
Module Design Checklist
When to Use This
Before publishing a new module or accepting a module PR — to verify the module meets the contract standard that allows consumers to upgrade without surprises and compose modules safely.
1. Interface Design
variable "retention_days" {
type = number
description = "Log retention in days. Must be one of: 1, 3, 7, 14, 30, 60, 90."
default = 30
validation {
condition = contains([1, 3, 7, 14, 30, 60, 90], var.retention_days)
error_message = "retention_days must be one of: 1, 3, 7, 14, 30, 60, 90."
}
}
2. Input Validation
3. Resource Naming and Tagging
4. For_each vs Count
# Wrong
resource "aws_iam_role" "worker" {
count = length(var.worker_names)
name = var.worker_names[count.index]
}
# Right
resource "aws_iam_role" "worker" {
for_each = toset(var.worker_names)
name = each.key
}
5. Outputs
6. Version Pinning
7. Examples Directory
8. Testing
Pre-Publish Gate
# Run before opening a module PR
cd modules/<module-name>
terraform fmt -recursive -check
terraform validate
terraform-docs markdown . > README.md
cd examples/complete && terraform init && terraform validate
Pitfalls
- Publishing a module with no
examples/ directory — consumers have to read the source to use it.
- Accepting
any typed variables — callers get no editor assistance and errors are cryptic.
- Using
count for resource sets that might have items added/removed — causes surprising resource replacement.
- Hardcoding the AWS region in a module — the consumer's provider configuration should own the region.
- Not marking sensitive outputs
sensitive = true — the value is printed in plan/apply output and CI logs.
See Also