GitHub Actions Workflows
July 12, 2025 ยท View on GitHub
This document describes all GitHub Actions workflows configured in this Terraform modules repository.
๐ Workflows Overview
| Workflow | Purpose | Trigger | Status |
|---|---|---|---|
| ๐ Terraform Validation | Terraform format and syntax validation | Push/PR to main | โ Active |
| ๐ Terraform Docs | Automatic documentation generation | Push/PR to main | โ Active |
| ๐งน MegaLinter | Code linting and formatting | Push/PR to main | โ Active |
| ๐ Automated Release | Automatic release creation | Push to main + changes | โ Active |
๐ Terraform Validation
File: .github/workflows/terraform-validation.yml
Purpose
Intelligent Terraform module validation that detects changes and executes validations only on affected components to optimize CI/CD time.
Triggers
- Push to main: Validates changes being merged
- Pull requests to main: Validates proposed changes (excludes draft PRs)
Key Features
๐ฏ Smart Change Detection
- Automatically detects which modules have been modified
- Identifies changes to main examples
- Only runs validations on affected components
๐ง Format Validation
- Runs
terraform fmt -check -recursivefrom repository root - Ensures all Terraform files follow consistent formatting standards
- Fails if any formatting issues are detected
โ Module Validation
- Validates only the modules that have been changed
- Runs
terraform initandterraform validateon each modified module - Automatically validates module-specific examples if they exist
๐ Example Validation
- Always validates main examples (
examples/) when any module changes - Validates module-specific examples (e.g.,
modules/aws-bastion/examples/) - Ensures examples remain functional after module updates
Workflow Jobs
detect-changes: Analyzes git diff to determine what changedterraform-fmt: Format validation from repository rootvalidate-modules: Matrix validation of changed modules + their examplesvalidate-examples: Matrix validation of main examplesterraform-validation-summary: Comprehensive reporting and final status
Example Output
โ
Terraform Format Check: Passed
โ
Module Validation: Passed
- Validated modules: aws-vpc aws-rds
โ
Examples Validation: Passed
๐ Changes Detected
- Modules changed: true
- Examples changed: false
- Any Terraform files changed: true
- Changed modules: aws-vpc aws-rds
Benefits
- โก Efficiency: Only validates changed components
- ๐ Comprehensive: Covers modules, examples, and formatting
- ๐ Transparent: Clear reporting and failure reasons
- ๐ Parallel: Uses matrix strategy for faster execution
- ๐ก๏ธ Reliable: Catches issues before they reach main branch
๐ Terraform Docs
File: .github/workflows/tf-docs.yml
Purpose
Automatically generates documentation for all Terraform modules using terraform-docs.
Triggers
- Push to main: Updates documentation after merge
- Pull requests to main: Generates docs for review (excludes draft PRs)
Features
- Automatic Generation: Updates
docs/MODULE.mdin each module - Git Synchronization: Automatically commits documentation changes
- Consistent Format: Uses standard template for all documentation
Benefits
- ๐ Always Updated Documentation: No outdated docs
- ๐ค Complete Automation: No manual intervention required
- ๐ Consistent Format: All documentation follows the same standard
๐งน MegaLinter
File: .github/workflows/mega-linter.yml
Purpose
Comprehensive linting and automatic fix application for multiple languages and formats.
Triggers
- Push to main: Validation after merge
- Pull requests to main: Validation of proposed changes
Key Features
- Multi-Language Linting: Support for Terraform, YAML, Markdown, JSON, etc.
- Auto-Fix: Automatically applies fixes when possible
- Detailed Reports: Generates comprehensive reports of issues found
- PR Integration: Creates automatic PRs with applied fixes
Configuration
- Apply Fixes: Enabled for pull requests
- Mode: Direct commit of fixes
- Cancellation: Concurrent workflows are automatically cancelled
Benefits
- ๐ฏ Code Quality: Maintains consistent standards
- ๐ง Auto-Fixes: Reduces manual work
- ๐ Visibility: Clear reports of quality issues
- ๐ Efficiency: Detects problems early in the process
๐ Automated Release
File: .github/workflows/release.yml
Purpose
Automates release creation based on changes in CHANGELOG.md and modules.
Triggers
- Push to main with changes in:
CHANGELOG.md.release-triggermodules/**
- Manual: Workflow dispatch with release type options
Features
- Automatic Release: Detects changes and creates appropriate releases
- Semantic Versioning: Support for major, minor, patch
- Changelog Validation: Verifies changelog is updated
- Manual Trigger: Allows manual releases with custom configuration
Manual Options
- Release Type: major, minor, patch
- Skip Changelog Check: Bypasses changelog validation
Benefits
- ๐ฏ Consistent Releases: Automated and predictable process
- ๐ Documentation: Changelog integration
- ๐ Flexibility: Both automatic and manual modes
- ๐ฆ Distribution: Facilitates adoption of new versions
๐ ๏ธ Configuration and Maintenance
Repository Requirements
- Module structure in
modules/directory - Main examples in
examples/directory - Module-specific examples in
modules/{module-name}/examples/ - Proper Terraform version files and lock files
Required Permissions
- contents: write - For automatic commits and releases
- pull-requests: write - For creating/updating PRs
- issues: write - For reporting issues
Monitoring
- All workflows include detailed reports
- Failures are clearly identified with specific reasons
- GitHub Step Summary provides executive summaries
Best Practices
- Keep Changelog Updated: For automatic releases
- Format Before Commit: Run
terraform fmt -recursivelocally - Test Examples: Validate examples before pushing
- Review Draft PRs: Mark as ready when prepared for CI
๐ง Troubleshooting
Common Failures
Terraform Format Issues
# Local solution
terraform fmt -recursive .
Module Validation Failures
# Local debug
cd modules/{module-name}
terraform init -backend=false
terraform validate
Example Validation Failures
# Local debug
cd examples/{example-name}
terraform init -backend=false
terraform validate
Logs and Debugging
- Each job provides detailed logs
- GitHub Step Summary includes executive summary
- Artifacts available for downloads (MegaLinter reports)
๐ Additional Resources
๐ค Contributing
To modify or add workflows:
- Edit files in
.github/workflows/ - Test locally when possible
- Validate YAML syntax
- Document changes in this file
- Test in PR before merging to main