A comprehensive template repository for creating Terraform/OpenTofu modules with best practices, automated testing, and CI/CD workflows.
- ποΈ OpenTofu/Terraform Support: Compatible with both OpenTofu and Terraform
- β Automated Testing: Terratest integration with Go-based tests
- π Auto-Documentation: terraform-docs integration with pre-commit hooks
- π Code Quality: Pre-commit hooks with formatting, validation, and linting
- π CI/CD Pipeline: GitHub Actions for testing and publishing
- π Example Configurations: Dev and prod example implementations
- π‘οΈ Security Scanning: Trivy integration for configuration security
- Use this template by clicking "Use this template" on GitHub
- Clone your new repository
- Customize the module files for your specific use case
- Update the testing configuration and examples
- Configure GitHub Actions secrets for CI/CD
.
βββ .github/
β βββ workflows/
β βββ terraform.yml # CI/CD pipeline
βββ .pre-commit-config.yaml # Pre-commit hook configuration
βββ .terraform-docs.yml # Terraform docs configuration
βββ .tflint.hcl # TFLint configuration
βββ examples/ # Usage examples
β βββ dev/ # Development environment example
β βββ prod/ # Production environment example
βββ test/ # Terratest suite
β βββ go.mod # Go module definition
β βββ module_test.go # Test implementation
βββ Makefile # Development commands
βββ main.tf # Main module configuration (to be created)
βββ variables.tf # Input variables (to be created)
βββ outputs.tf # Output definitions (to be created)
βββ versions.tf # Provider version constraints (to be created)
βββ README.md # This file
The following section contains auto-generated documentation for this Terraform module using terraform-docs:
module "cloudrun_ai_app" {
source = "openteams-ai/cloudrun-ai-app/gcp"
version = "~> 1.0"
project_id = "my-gcp-project"
region = "us-central1"
customer_name = "acme-corp"
domain_name = "acme.example.com"
# Application configuration
app_image = "gcr.io/my-project/ai-app:latest"
app_env_vars = {
AI_BACKEND_URL = "https://api.openai.com/v1"
MCP_SERVER_URL = "https://mcp.example.com"
}
}| Name | Version |
|---|---|
| terraform | >= 1.5 |
No providers.
No modules.
No resources.
No inputs.
No outputs.
This README uses terraform-docs to automatically generate and maintain module documentation. The content between <!-- BEGIN_TF_DOCS --> and <!-- END_TF_DOCS --> is automatically generated.
- Auto-generate: Run
make docsto update the terraform-docs section - Manual content: Edit sections outside the terraform-docs markers
- Configuration: Modify
.terraform-docs.ymlto customize the generated content
- The
make docscommand uses Docker to run terraform-docs - It reads your Terraform files (main.tf, variables.tf, outputs.tf, etc.)
- Generates documentation in Markdown format
- Injects the content between the
<!-- BEGIN_TF_DOCS -->and<!-- END_TF_DOCS -->markers - Preserves all custom content outside these markers
Important: Never manually edit content between the terraform-docs markers as it will be overwritten.
This template includes comprehensive testing setup using Terratest. The tests validate:
- Infrastructure provisioning
- Resource configuration
- Input validation
- Multi-environment scenarios
The template includes three types of tests:
- Terraform Validation: Tests that the main module can be initialized and validated
- Examples Validation: Tests that example configurations are syntactically correct
- Module Functionality: Placeholder tests that demonstrate assertion patterns
Note: These are validation-only tests that don't deploy actual infrastructure. When developing your module, replace the placeholder tests with actual functionality tests as needed.
# Run all tests
make test
# Run specific test functions
cd test && go test -v -run TestDevExample| Command | Description |
|---|---|
make help |
Display available make targets with descriptions |
make init |
Initialize OpenTofu and install pre-commit hooks |
make fmt |
Format all Terraform files |
make validate |
Validate Terraform configuration |
make lint |
Run all linting checks |
make test |
Run the full test suite |
make docs |
Generate documentation with terraform-docs |
make clean |
Clean up temporary files and directories |