π― Objective
- Build a fully automated system that:
- Provisions infrastructure using Terraform
- Detects unauthorized/manual infrastructure changes (drift)
- Automatically remediates drift
- Sends Slack notifications
- Manages GitHub issues for audit tracking
- Supports dev and prod environments All using GitHub Actions as the automation engine
π Project Architecture
The infrastructure includes:
- VPC with public & private subnets
- NAT Gateway for outbound internet
- Autoscaling group across availability zones
- Separate backend state for dev & prod (S3 + DynamoDB locking)
- GitHub repository as the single source of truth
Terraform code is stored in GitHub, and GitHub Actions workflows automate:
- Provisioning
- Drift detection
- Destruction
π How Drift Detection Works
Terraformβs plan command supports detailed exit codes:
0 β No changes
2 β Drift detected
1 β Error
The drift detection workflow runs:
terraform plan -detailed-exitcode
If exit code 2 is returned:
- Drift is confirmed
- terraform apply -auto-approve runs automatically
- Infrastructure is restored to the desired state
- Slack notification is sent
- GitHub issue is updated/closed
This enforces:
Terraform code = Single Source of Truth
π§ͺ Live Drift Testing
A manual change was made directly in AWS (modifying resource tags).
Result:
GitHub Actions detected drift
Terraform re-applied correct configuration
Tags reverted automatically
Slack notification confirmed remediation
GitHub issue lifecycle updated
This demonstrated real production-level drift governance.
π Security & Best Practices Implemented
- AWS credentials stored in GitHub Secrets
- Slack webhook stored securely
- Separate backend state for dev & prod
- DynamoDB locking to prevent concurrent state corruption
- Scheduled Cron-based drift monitoring
- Manual approvals for production workflows
π Key Takeaways
β Drift detection prevents configuration inconsistencies
β GitHub Actions can fully automate infrastructure lifecycle
β Terraform exit codes enable intelligent CI/CD logic
β Slack integration improves operational visibility
β GitHub Issues provide audit traceability
β IaC must always be treated as the single source of truth
Top comments (0)