Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions .github/workflows/tf-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
paths:
- 'infra/**'
- 'modules/**'
- '.github/workflows/terraform-*.yml'
workflow_dispatch:

Expand Down Expand Up @@ -51,11 +52,11 @@ jobs:
exit 0
fi

# Find all changed files in infra/
changed_files=$(git diff --name-only "$BASE_REF" "$HEAD_REF" -- infra/ || echo "")
# Find all changed files in infra/ and the shared modules they consume
changed_files=$(git diff --name-only "$BASE_REF" "$HEAD_REF" -- infra/ modules/ || echo "")

if [ -z "$changed_files" ]; then
echo "No changes detected in infra/"
echo "No changes detected in infra/ or modules/"
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "changed_dirs=[]" >> $GITHUB_OUTPUT
exit 0
Expand Down Expand Up @@ -132,6 +133,9 @@ jobs:
apply:
name: Apply Infrastructure
needs: discover-changes
# Without this gate an empty change set yields an empty filter, and
# `terragrunt run --all -- apply -auto-approve` then applies every unit.
if: needs.discover-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
environment:
name: production
Expand Down Expand Up @@ -308,10 +312,10 @@ jobs:
echo "Manual deployment - all modules processed"
echo ""
elif [ "$has_changes" = "true" ]; then
echo "Changes detected in infra/ but not in terragrunt module directories"
echo "Changes detected in infra/ or modules/ but not in a specific terragrunt directory - applying everything"
echo ""
else
echo "No changes detected in infra/"
echo "No changes detected in infra/ or modules/"
echo ""
fi

Expand All @@ -323,6 +327,9 @@ jobs:
echo ""
echo "Infrastructure changes have been applied to production."
exit 0
elif [[ "$apply_result" == "skipped" ]]; then
echo "⏭️ Deployment skipped - no infrastructure changes to apply."
exit 0
else
echo "❌ Deployment failed"
echo ""
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/tf-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
- main
paths:
- 'infra/**'
- '.github/workflows/terraform-*.yml'
- 'modules/**'
- '.github/workflows/tf-*.yml'

permissions:
contents: read
Expand Down Expand Up @@ -43,11 +44,11 @@ jobs:
BASE_REF="${{ github.event.pull_request.base.sha }}"
HEAD_REF="${{ github.sha }}"

# Find all changed files in infra/
changed_files=$(git diff --name-only "$BASE_REF" "$HEAD_REF" -- infra/ || echo "")
# Find all changed files in infra/ and the shared modules they consume
changed_files=$(git diff --name-only "$BASE_REF" "$HEAD_REF" -- infra/ modules/ || echo "")

if [ -z "$changed_files" ]; then
echo "No changes detected in infra/"
echo "No changes detected in infra/ or modules/"
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "changed_dirs=[]" >> $GITHUB_OUTPUT
exit 0
Expand Down Expand Up @@ -495,10 +496,10 @@ jobs:
echo "$changed_dirs" | jq -r '.[]' | sed 's/^/ - /'
echo ""
elif [ "$has_changes" = "true" ]; then
echo "Changes detected in infra/ but not in terragrunt module directories"
echo "Changes detected in infra/ or modules/ but not in a specific terragrunt directory - validating everything"
echo ""
else
echo "No changes detected in infra/"
echo "No changes detected in infra/ or modules/"
echo ""
fi

Expand Down Expand Up @@ -549,9 +550,9 @@ jobs:
});
body += '\n';
} else if (hasChanges) {
body += '### ℹ️ Changes detected in `infra/` but not in terragrunt module directories\n\n';
body += '### ℹ️ Changes detected in `infra/` or `modules/` but not in a specific terragrunt directory - everything was validated\n\n';
} else {
body += '### ℹ️ No changes detected in `infra/`\n\n';
body += '### ℹ️ No changes detected in `infra/` or `modules/`\n\n';
}

const allPassed = validateResult === 'success' && planResult === 'success';
Expand Down
Loading