π Welcome to the Caylent Terraform Module Hub
Your one-stop shop for production-grade, security-hardened, and fully tested Terraform modulesβpurpose-built for AWS and the modern cloud.
Whether you're a platform engineer, DevOps specialist, cloud architect, or developer β this repo is built to help you:
- π Deliver faster: Instantly adopt proven modules for AWS and common integrations like GitHub, and more to come.
- π Ship with confidence: Every module is policy-enforced, security-audited, and functionally tested.
- π Integrate seamlessly: Built for AWS-first platforms, but extensible to broader cloud-native and SaaS ecosystems.
- β‘ Start fast: Browse, copy, and apply modules with minimal setup. See Getting Started to dive in.
Most users simply consume modulesβno customization required.
Ready to move? Jump to Getting Started or explore the Module Types.
To use any module from this repo, reference it directly in your Terraform configuration using the Git source and a version tag:
module "generic_skeleton" { source = "git::https://github.com/caylent-solutions/terraform-modules.git//skeletons/generic-skeleton?ref=skeletons/generic-skeleton/v1.0.0" # ...module inputs... }
- Replace the module path (
skeletons/generic-skeleton) with the one you need. - Replace the version (
v1.0.0) with the exact tag to pin the module version.
β οΈ Pinning is required β Terraformβsgitsource does not support version ranges.
Youβll soon be able to consume modules directly via a public Caylent registry:
- Native support for version constraints (e.g.,
~> 1.2) - No authentication required
- Backed by this GitHub repo
- Fully audited, tested, and production-ready modules
Stay tuned for release announcements.
- Who This Repo Is For
- How to Use: Sourcing & Importing Modules
- Coming Soon: Caylent Public Terraform Registry
- Repository Structure
- Governance
- Security
- Repository Principles and Strategy
- Module Types
- Terraform Provider Strategy
- Module Structure
- Testing Requirements
- Configuration
- Getting Started
- Workflow Development and Testing
- Repository Health Checks
- CI/CD Workflows Overview
- Contribution Process
- Documentation
A clear, logical structure for all modules and supporting files:
.
βββ generics
β βββ utilities/ # Terraform modules
βββ providers
β βββ aws/
β β βββ collections/ # Terraform modules
β β βββ primitives/ # Terraform modules
β β βββ references/ # Terraform modules
β βββ github/
β βββ collections/ # Terraform modules
β βββ primitives/ # Terraform modules
β βββ references/ # Terraform modules
βββ skeletons # Terraform modules
βββ generic-skeleton/
This repository implements governance policies to ensure consistent and maintainable code:
- Single Module Policy: PRs must change only one Terraform module at a time
- Separation Policy: PRs must either modify exactly one module OR only non-module files (not both)
- Empty PR Policy: PRs must contain at least one file change
- Module Type Policies: Each module type has specific content requirements
- Module Structure Policies: All modules must follow a standardized structure
- File Organization Policies: Terraform declarations must be in specific files
These policies are enforced using Open Policy Agent (OPA) in the CI/CD pipeline.
This repository implements comprehensive security controls:
- GitHub Actions Security: All third-party actions are SHA-pinned to prevent supply chain attacks
- External Contributor Protection: External contributors cannot modify workflow files
- Automated Security Scanning: CodeQL analysis runs on all pull requests
- Terraform Security Scanning:
tfsecscans every Terraform module change for security issues - Environment Isolation: External contributor tests run in protected environments
- Manual Approval Gates: Multiple approval points ensure code quality and security
- Action Allowlist: Only pre-approved GitHub Actions can be used in workflows
Security is managed through automated scripts in the security-scripts/ directory. Use make github-actions-security to update action allowlists.
This monorepo is governed by the following principles, which guide all module and service development:
Each module or service in this monorepo is designed to be self-contained, including everything necessary to deploy, test, and validate itself in isolation. This ensures autonomy, reproducibility, and a complete SDLC for every module. See Self-Contained Repository Deployment Principle for details.
Every module or service is focused on a single responsibility, producing a single, environment-agnostic artifact or service. This aligns with the Single Responsibility Principle and supports modular, maintainable, and scalable infrastructure. See Single Purpose Repository Principle for details.
- All cloud, SaaS, and stateful resources are managed via Terraform modules in this monorepo.
- Module types include: Primitive, Utility, Reference, and Client Wrapper modules (see below).
- Modules must be client- and application-agnostic unless explicitly a client wrapper.
- All modules must be created using the latest skeleton and follow all OPA policies, structure, and testing requirements defined in this repo.
- All modules must be semantically versioned and released via CI/CD.
- Use official Terraform providers unless a fork is required for missing features/bugfixes (see CONTRIBUTING.md for provider forking strategy).
Terragrunt may be used in downstream consumer repositories to orchestrate deployments of modules from this monorepo. However, all Terraform code and module logic must reside in this repo, and Terragrunt HCL should only be used for orchestration, not for defining resource logic.
This repository supports several types of Terraform modules, each with a specific purpose and scope:
- Primitive Modules:
- Manages a single major resource type from a provider (e.g., S3, ECS, EC2).
- These modules are the most complex and where most raw development occurs.
- Utility Modules:
- Adds opinionated functionality (e.g., naming/tagging) or provides data-only structures (such as resource naming constraints for every AWS resource).
- Collection Modules:
- A composition of primitive modules and/or other collection modules.
- They provide an opinionated, specialized set of resources to support a use case (e.g., EKS cluster integrated with SumoLogic or Datadog).
- They do not provide a full reference architecture.
- Reference Modules:
- Provides a fully baked, production-ready service that is secure, observable, follows best practices, and modern architecture patterns.
- Client Wrapper Modules:
- Client-specific wrapper that imports reference modules and adds custom logic. Must live in the clientβs repo and follow the same structure/testing standards.
All modules must:
- Use the latest skeleton
- Pass all OPA policies and CI/CD checks
- Be fully tested (rego and Terratest)
- Be semantically versioned and released via CI/CD
- Use Apache 2.0 license unless client-specific
- Always use the latest stable official provider for all resources.
- If a required feature/bugfix is missing, fork the provider, follow best practices for forking, and upstream changes when possible. See CONTRIBUTING.md for the full provider forking workflow.
All modules must follow a standardized structure:
- Required files in the root directory (main.tf, variables.tf, etc.)
- Examples directory with at least one example implementation
- Tests directory with corresponding test directories for each example
- Documentation in README.md and TERRAFORM-DOCS.md
See Module Structure and Module Policies for detailed requirements.
All modules must include comprehensive functional tests using the Terraform Terratest Framework:
- Tests for each example implementation
- Common tests that verify basic functionality
- Tests that validate the module's core features
- Tests that ensure inputs are properly processed
See Module Testing for detailed testing requirements and examples.
All monorepo automation is configured through a single centralized file:
monorepo-config.json
This file defines module types, path patterns, policy directories, and other configuration used by all automation scripts. See Monorepo Configuration for details.
Individual Terraform modules use the Caylent Package Manager (CPM) for standardized automation tasks. CPM provides:
- Versioned Automation: Pin exact versions of testing, linting, and validation tasks
- Consistent Tooling: Same automation across all modules without code duplication
- Single Source of Truth: Centralized Make targets managed via the cpm-terraform-modules-monorepo package
- Ephemeral Dependencies: All CPM packages are synced to
.packages/and.repo/(git-ignored, never committed)
Each module contains:
Makefile- CPM orchestration withcpm-configuretarget (static, rarely changes).cpmenv- CPM configuration (versions, URLs, settings)
How it works:
- The base CPM Makefile provides the
cpm-configuretarget - Running
make cpm-configuresyncs the cpm-terraform-modules-monorepo package to.packages/ - This package provides all module automation tasks (test, lint, format, docs, security)
- Tasks are only available after
make cpm-configurehas been run
See CPM Documentation for complete details on how CPM works.
Follow these steps to get up and running as a contributor or consumer:
This repository uses ASDF v0.15.0 to manage tool versions:
# Install required tools for the monorepo
make install-tools- Clone the repository
- Install required tools:
make install-tools - Configure the environment:
make configure - Create a new module from the skeleton:
cp -r skeletons/generic-skeleton your/new/module - Enter your module directory and configure CPM:
cd your/new/module && make cpm-configure- This syncs the automation package to
.packages/and makes CPM tasks available
- This syncs the automation package to
- Install module dependencies:
make install- This installs Go modules and the tftest CLI tool
- Implement your module following the structure requirements
- Use CPM-provided automation tasks (from the module directory):
make test- Run all Terratest testsmake test-common- Run common tests onlymake tf-format- Check Terraform formattingmake tf-lint- Lint Terraform filesmake tf-docs- Generate documentationmake tf-security- Run security scansmake go-lint- Lint Go test filesmake go-format- Format Go test filesmake clean- Clean Terraform state
- Validate your module from repo root:
make module-validate MODULE_PATH=your/new/module MODULE_TYPE=module_type
- Test all non-Terraform code:
make test-all-non-tf-module-code(from repo root) - Submit a PR
Note: Module automation tasks are provided by the cpm-terraform-modules-monorepo package and are only available after running make cpm-configure followed by make install. The base CPM Makefile only provides cpm-configure and related CPM management targets.
For developers working on the main validation workflow (.github/workflows/main-validation.yml):
# Test all 6 merge approval job variations in dry run mode
make test-main-validation-workflowThis comprehensive test triggers all possible merge approval scenarios to validate workflow changes before deployment. See Main Validation Script Documentation for details.
For repository maintainers, a comprehensive test suite is available to validate all Terraform modules:
# Test all Terraform modules (runs weekly via GitHub Actions)
make test-all-terraform-modulesThis task runs the full validation suite (documentation, formatting, linting, OPA policies, planning, security, and tests) across all modules in parallel. It's designed for CI/CD use and not required for regular development.
For detailed contribution guidelines, see docs/CONTRIBUTING.md.
This repository uses a multi-stage, automated CI/CD pipeline to ensure code quality, security, and compliance for all contributions. The workflows support both production and dry run (safe testing) modes.
- PR Validation (
pr-validation.yml): Entry point for all pull requests. Detects contributor type (internal/external), enforces workflow file protection, and routes PRs to the correct validation workflow based on whether Terraform modules or non-Terraform code are changed. - Main Validation (
main-validation.yml): Core workflow for PR approval, merge decisions, and release orchestration. Handles both Terraform and non-Terraform changes, supports dry run mode, and manages merge approval routing. - Release (
release.yml): Handles both Terraform and non-Terraform releases. Uses custom logic for module versioning andpython-semantic-releasefor non-Terraform code. Automates changelog generation and tagging. - CodeQL Analysis (
codeql-analysis.yml): Runs automated security scanning on all pushes and PRs. - Weekly Module Health Check (
weekly-module-health-check.yml): Runs comprehensive tests on all Terraform modules weekly and on demand.
- Workflow File Protection: External contributors cannot modify workflow files. Internal contributors must follow the SDLC process for workflow changes.
- Automated Security Scanning: CodeQL analysis runs on all PRs and pushes.
- Manual Approval Gates: Maintainers must approve PRs and test execution for external contributors.
- Environment Isolation: Tests for external contributors run in protected environments.
- Action Allowlist: Only SHA-pinned, pre-approved GitHub Actions are permitted.
- Security Check: Validates contributor type and workflow file changes.
- Change Detection: Determines if the PR changes a Terraform module or only non-module files.
- Validation: Runs comprehensive policy, linting, formatting, documentation, and security checks.
- Testing: Executes full test suite (automatic for internal, manual approval for external contributors).
- Approval & Merge: Maintainers review and approve. PRs are auto-merged after approval (never merge manually).
- Release: Automated versioning (based on PR title) and changelog for both Terraform and non-Terraform code.
See Workflow Logic and Main Validation SDLC Guide for full details.
- Follow module structure requirements and module policies.
- Implement comprehensive tests using Terraform Terratest Framework.
- Validate and test locally before submitting a PR.
- Format your PR title with conventional commit prefix (
feat:,fix:, etc.) - this determines the version bump. - Never manually merge PRs - the pipeline automatically merges after approval.
- Automated validation, testing, and release via CI/CD.
- Linting, tests, and policy checks as appropriate.
- Format your PR title with conventional commit prefix (
feat:,fix:, etc.) - this determines the version bump. - Never manually merge PRs - the pipeline automatically merges after approval.
- Uses
python-semantic-releasefor versioning and changelog. - Automated validation and release via CI/CD.
- Internal: Direct branch, push, and PR workflow. Tests run automatically.
- External: Fork, branch, PR workflow. Cannot modify workflows. Tests require manual approval.
See docs/CONTRIBUTING.md for detailed instructions.
- Contributing Guidelines - How to contribute and SDLC process
- PR Title-Based Versioning - How PR titles determine version bumps
- Workflow Logic Documentation - Detailed CI/CD flow explanation
- Main Validation SDLC Guide - SDLC process for workflow maintenance
- AWS Authentication Integration - How AWS authentication works with GitHub Actions for module testing
- Terraform Module Structure
- Terraform Module Policies
- Terraform Module Testing
- Module Validation
- Monorepo Configuration
- Scripts Documentation Index - Complete index of all scripts
- GitHub Actions Security Scripts - Secure GitHub Actions management
- Detect Proposed Git Repo Changes
- Go Format
- Go Lint
- Go Unit Test
- Install Tools
- Main Validation - End-to-end workflow testing
- Module Type Validator
- Module Validator
- Rego Unit Test
- Terraform File Collector