Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Terraform CI

on:
pull_request:
branches:
- main

jobs:
plan:
name: Terragrunt Plan
runs-on: ubuntu-latest
outputs:
plan_status: ${{ steps.plan-status.outputs.status }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false

- name: Terragrunt Plan
id: plan-status
run: |
mkdir -p logs
terragrunt plan-all | tee logs/plan.log
echo "status=success" >> $GITHUB_OUTPUT

- name: Upload Plan Logs
uses: actions/upload-artifact@v4
with:
name: terragrunt-plan-logs
path: logs/

verify-artifacts:
name: Verify Plan and Artifact Integrity
runs-on: ubuntu-latest
needs: [plan]
if: always()
outputs:
status: ${{ steps.validate.outputs.status }}
steps:
- name: Download Plan Artifacts
uses: actions/download-artifact@v4
with:
name: terragrunt-plan-logs
path: ./logs

- name: Validate Plan Output
id: validate
run: |
echo "��� Validating Terragrunt Plan Output..."
mkdir -p output
if find ./logs -type f -name '*.log' -print0 | xargs -0 grep -iE "Error:|Failed|Denied|Permission|Authentication|Timeout|issue|Unauthenticated|Unauthorized|Forbidden|Connection refused|Service unavailable|Rate limit|Access denied"; then
echo "::error::Detected error(s) in plan logs. Failing verification."
find ./logs -type f -name '*.log' -exec grep -iE "Error:|Failed|Denied|Permission" {} \; > output/error_summary.txt
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
else
echo "✅ Plan verification passed successfully."
echo "status=success" >> $GITHUB_OUTPUT
fi

- name: Upload Error Summary (if failed)
if: failure()
uses: actions/upload-artifact@v4
with:
name: plan-error-summary
path: output/error_summary.txt

apply:
name: Terraform Apply
runs-on: ubuntu-latest
needs: [verify-artifacts]
if: needs.verify-artifacts.result == 'success'
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false

- name: Terraform Apply
run: terragrunt apply-all