Terraform module for AWS Lambda with opinionated defaults for IAM, logging, VPC, event sources, and deployments. Published to the Terraform Registry.
main.tf— Twoaws_lambda_functionresources (normal + external lifecycle for CodeDeploy/CLI updates), selected viavar.ignore_external_function_updatesiam.tf— IAM role, conditional policy attachments (VPC, tracing, Lambda Insights, SSM, CloudWatch Logs)variables.tf— REQUIRED section first, then OPTIONAL with section commentsoutputs.tf— Core outputs (arn, function_name, role_name, role_arn, invoke_arn, version, log group, log group arn)cloudwatch_logs.tf,cloudwatch_event_rules.tf,event_source_mappings.tf,sns_subscriptions.tf— Feature-specific resourcesmodules/deployment/— CodePipeline/CodeDeploy submodule
terraform fmtenforced via pre-commit- Alphabetical attribute ordering within resources
- Dynamic blocks:
for_each = var.x == null ? [] : [var.x] - Count-based conditional resources:
count = var.feature_enabled ? 1 : 0 - Locals for computed values (function ARN, role name with 64-char limit, log group name)
- Each feature area has its own .tf file with local variables as needed
- snake_case naming
- Detailed descriptions in imperative style ("A unique name...", "Enables your Lambda function to...")
nulldefault for optional object variables- Types always explicit
- IAM role:
${function_name}-${region}(truncated to 64 chars) - Log group:
/aws/lambda/${function_name} - Resource name prefixes:
${var.function_name}-<feature>
Conventional commits enforced by CI: feat:, fix:, chore:, refactor:, docs:, ci:
- Lowercase subject, no period at end
- Semantic PR titles required
- Semantic versioning via git tags (e.g.
v8.6.0) make release BUMP=minorto bump, tag, and create GitHub release
All in examples/. Each uses module "fixtures" from examples/fixtures/ for shared test data (lambda.zip, random function name). Examples serve as integration tests — run terraform apply to verify.
Runtime-specific examples (examples/runtimes/) use Makefiles with standardized targets (help, package, tf, clean). Build logic stays in the Makefile, infrastructure in Terraform.
- pre-commit: terraform_fmt, terraform_validate, terraform_tflint, terraform_trivy, terraform_docs
- GitHub Actions: static-checks (pre-commit matrix with min+max TF versions), pr-title (semantic), stale
- terraform_docs: auto-generates README.md input/output tables from variables.tf/outputs.tf
- trivy: blocks HIGH/CRITICAL findings; use
#trivy:ignore:AVD-xxxwith justification comment - tflint: AWS plugin enabled;
invalid_handlerandinvalid_runtimerules disabled
- Add variable to
variables.tf(in alphabetical order within the OPTIONAL section) - Add dynamic block to BOTH
aws_lambda_functionresources inmain.tf - Add IAM permissions to
iam.tfif the feature needs them (conditional on the variable) - Add/update an example in
examples/ - Run
pre-commit run -ato update README.md and validate - Run
terraform applyin the example directory to verify
- Edit text between
<!-- BEGIN_TF_DOCS -->and<!-- END_TF_DOCS -->in README.md — it is auto-generated by terraform_docs - Run
terraform applyin CI — examples are tested manually - Skip pre-commit hooks (
--no-verify) — fix the underlying issue instead - Use
filebase64sha256()for deployment zips without afileexists()guard — CI runs validate without build artifacts
- Terraform >= 1.5.7
- AWS provider >= 6.0