This repository implements a comprehensive infrastructure validation pipeline using GitHub Actions. The pipeline performs various security, cost, and quality checks on infrastructure code, particularly focusing on Terraform configurations.
flowchart TB
subgraph "Pre-Commit Phase"
PC[Pre-commit Hooks]
GT[GitGuardian Secrets Check]
TM[Threat Modeling]
PC --> GT
PC --> TM
end
subgraph "Infrastructure Validation"
TF[Terraform Validation]
TS[TFSec Analysis]
TL[TFLint Checks]
IC[Infracost Analysis]
TF --> TS
TF --> TL
TF --> IC
end
subgraph "Security Scanning"
SAST[Static Analysis]
DAST[Dynamic Analysis]
DEP[Dependency Scanning]
SC[Supply Chain Security]
SAST --> DEP
DAST --> DEP
DEP --> SC
end
subgraph "Container & K8s Security"
CS[Container Scanning]
KS[Kubernetes Security]
PS[Policy Scanning]
CS --> KS
KS --> PS
end
subgraph "Cloud Security"
AWS[AWS Security]
GCP[GCP Security]
MC[Multi-Cloud Controls]
AWS --> MC
GCP --> MC
end
PC --> TF
GT --> SAST
TF --> CS
CS --> AWS
KS --> MC
style Pre-Commit fill:#d0e1f9
style Infrastructure fill:#e3f2fd
style Security fill:#ffebee
style Container fill:#f3e5f5
style Cloud fill:#e8f5e9
The pipeline runs automatically on:
- Pull requests that modify infrastructure files (
.tf,.tfvars,.hcl,Dockerfile) - Push events to main/master branch with changes to infrastructure files
- Changes to GitHub workflow files or pre-commit configuration
- Performs deep security scanning of the entire git history
- Detects secrets, credentials, and sensitive information
- Requires
GITGUARDIAN_API_KEYsecret to be configured
- Scans Terraform code for security issues and best practice violations
- Generates JSON output with detailed findings
- Runs in soft-fail mode to avoid blocking pipelines
- Includes statistics about the scan results
The pipeline includes comprehensive cost management through Infracost:
- Generates cost estimates for infrastructure changes
- Compares costs between base and PR branches
- Posts detailed cost difference comments on PRs
- Requires
INFRACOST_API_KEYsecret
- Tracks cost changes on the main/master branch
- Updates Infracost Cloud with latest cost data
- Continues even if policy checks fail
- Updates PR status in Infracost when PRs are merged or closed
- Maintains accurate cost history
The pipeline runs a comprehensive suite of checks in a Docker container:
-
Pre-commit Hooks
- Runs all configured pre-commit checks
- Ensures code quality and formatting standards
-
TFLint
- Lints Terraform files in all directories
- Validates against Terraform best practices
-
Terraform Operations
- Runs
terraform initwith backend disabled - Validates Terraform configurations
- Checks for required_providers blocks in all Terraform files
- Runs
The following secrets must be configured in your GitHub repository:
GITGUARDIAN_API_KEY: For security scanningINFRACOST_API_KEY: For cost estimation and tracking
- Concurrency Control: Automatically cancels redundant runs
- Caching: Uses GitHub Actions cache for Docker builds
- Comprehensive Validation: Checks both security and functionality
- Cost Awareness: Maintains visibility of infrastructure costs
- Pull Request Integration: Provides feedback directly on PRs
- Terraform files must include
required_providersblocks - Docker must be available in the GitHub Actions environment
- Appropriate secrets must be configured
- Pre-commit configuration must be present in
.pre-commit-config.yaml
- TFSec runs in soft-fail mode to provide warnings without blocking
- Main branch Infracost updates continue even with policy failures
- Infrastructure validation fails if any required_providers blocks are missing
- Clear error messages are provided for failed checks
The pipeline runs automatically based on the configured triggers. No manual intervention is required unless errors are detected.
- Make your infrastructure changes
- Create a pull request
- Review the automated checks:
- Security scan results
- Cost impact analysis
- Infrastructure validation outcomes
- Address any issues identified by the pipeline
- Merge when all checks pass
When contributing to this repository, ensure your changes:
- Include appropriate Terraform provider configurations
- Follow security best practices
- Consider cost implications
- Pass all pipeline checks