-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonorepo.yml
More file actions
205 lines (174 loc) · 6.52 KB
/
monorepo.yml
File metadata and controls
205 lines (174 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Advanced Monorepo DriftHound Workflow
# This example demonstrates advanced features for complex monorepo setups:
# - Multiple cloud providers (AWS, GCP, Azure)
# - Different authentication methods per scope
# - Environment-specific configurations
# - Conditional Slack notifications
name: Monorepo Drift Detection
on:
schedule:
# Check production every 6 hours
- cron: '0 */6 * * *'
# Check staging daily at 9am
- cron: '0 9 * * *'
workflow_dispatch:
inputs:
environment:
description: 'Environment to check (production, staging, or all)'
required: true
default: 'all'
type: choice
options:
- all
- production
- staging
jobs:
prepare-matrix:
name: Prepare Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
scope-count: ${{ steps.generate.outputs.scope-count }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine scope filter
id: filter
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
ENV="${{ github.event.inputs.environment }}"
elif [[ "${{ github.event.schedule }}" == "0 9 * * *" ]]; then
# Daily cron - check staging
ENV="staging"
else
# Default - check production
ENV="production"
fi
if [[ "$ENV" == "all" ]]; then
echo "scope-filter=" >> $GITHUB_OUTPUT
else
# Filter scopes by environment name pattern
echo "scope-filter=" >> $GITHUB_OUTPUT
echo "environment=$ENV" >> $GITHUB_OUTPUT
fi
- name: Generate matrix
id: generate
uses: ./drifthound-action/matrix@v1
with:
config-file: 'drifthound.yaml'
scope-filter: ${{ steps.filter.outputs.scope-filter }}
drift-check-aws:
name: AWS - ${{ matrix.name }}
runs-on: ubuntu-latest
needs: prepare-matrix
if: contains(matrix.name, 'aws')
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Run drift detection
uses: ./drifthound-action@v1
with:
drifthound-url: ${{ secrets.DRIFTHOUND_URL }}
drifthound-token: ${{ secrets.DRIFTHOUND_TOKEN }}
scope: ${{ matrix.name }}
drift-check-gcp:
name: GCP - ${{ matrix.name }}
runs-on: ubuntu-latest
needs: prepare-matrix
if: contains(matrix.name, 'gcp')
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Run drift detection
uses: ./drifthound-action@v1
with:
drifthound-url: ${{ secrets.DRIFTHOUND_URL }}
drifthound-token: ${{ secrets.DRIFTHOUND_TOKEN }}
scope: ${{ matrix.name }}
drift-check-azure:
name: Azure - ${{ matrix.name }}
runs-on: ubuntu-latest
needs: prepare-matrix
if: contains(matrix.name, 'azure')
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Run drift detection
uses: ./drifthound-action@v1
with:
drifthound-url: ${{ secrets.DRIFTHOUND_URL }}
drifthound-token: ${{ secrets.DRIFTHOUND_TOKEN }}
scope: ${{ matrix.name }}
summary:
name: Summary
runs-on: ubuntu-latest
needs: [prepare-matrix, drift-check-aws, drift-check-gcp, drift-check-azure]
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check results
id: check
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
echo "has-failures=true" >> $GITHUB_OUTPUT
echo "status=failure" >> $GITHUB_OUTPUT
else
echo "has-failures=false" >> $GITHUB_OUTPUT
echo "status=success" >> $GITHUB_OUTPUT
fi
- name: Display summary
run: |
echo "## Drift Detection Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Total scopes:** ${{ needs.prepare-matrix.outputs.scope-count }}" >> $GITHUB_STEP_SUMMARY
echo "- **Status:** ${{ steps.check.outputs.status }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check individual job logs for detailed results." >> $GITHUB_STEP_SUMMARY
# Example: Create GitHub issue if drift detected on main branch
# Note: DriftHound sends Slack notifications via slack_channel config
- name: Create issue on drift
if: steps.check.outputs.has-failures == 'true' && contains(github.ref, 'main')
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚨 Infrastructure Drift Detected in Monorepo',
body: `Drift was detected across multiple cloud providers.
**Summary:**
- Total scopes checked: ${{ needs.prepare-matrix.outputs.scope-count }}
- Status: ❌ One or more checks failed
**Next Steps:**
1. Review drift details in [DriftHound](${{ secrets.DRIFTHOUND_URL }})
2. Check individual scope results in the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
3. Reconcile infrastructure state
DriftHound automatically sends notifications to configured Slack channels.`,
labels: ['infrastructure', 'drift', 'monorepo']
});