Skip to content

Commit fcfc16c

Browse files
enchanment for terraform-provider-aquasec nightly workflow
implementation: - Added branch context to Power Automate webhook - Improved error handling and logging - Updated dependencies to latest versions
1 parent 00abd78 commit fcfc16c

File tree

2 files changed

+111
-48
lines changed

2 files changed

+111
-48
lines changed

.github/workflows/nightly.yml

Lines changed: 110 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ jobs:
1616
uses: actions/setup-go@v5
1717
with:
1818
go-version: '1.18'
19-
id: go
2019

21-
- name: Check out code into the Go module directory
20+
- name: Check out code
2221
uses: actions/checkout@v4
2322

2423
- name: Get dependencies
25-
run: |
26-
go mod download
24+
run: go mod download
2725

2826
- name: Build
29-
run: |
30-
go build -v .
27+
run: go build -v .
3128

3229
drift:
3330
name: "Drift Detection (TF ${{ matrix.terraform }})"
@@ -37,12 +34,11 @@ jobs:
3734
max-parallel: 1
3835
fail-fast: false
3936
matrix:
40-
terraform: [
41-
'0.15.5',
42-
'0.14.11',
43-
'1.1.2',
44-
'1.5.3'
45-
]
37+
terraform:
38+
- '0.15.5'
39+
- '0.14.11'
40+
- '1.1.2'
41+
- '1.5.3'
4642
env:
4743
TF_VAR_aquasec_url: ${{ secrets.AQUA_URL }}
4844
TF_VAR_aquasec_username: ${{ secrets.AQUA_USER }}
@@ -77,13 +73,20 @@ jobs:
7773
terraform plan -input=false -detailed-exitcode -out=tfplan.binary
7874
exitcode=$?
7975
echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
80-
# Fail for both drift (2) and error (1)
76+
# exit code 0 = no changes, 2 = changes (drift detected), 1 = error
8177
if [ "$exitcode" -ne 0 ]; then
8278
exit $exitcode
8379
fi
8480
85-
outputs:
86-
drifted: ${{ steps.plan.outputs.exitcode }}
81+
- name: Write result file
82+
run: |
83+
echo "{\"version\":\"${{ matrix.terraform }}\",\"exitcode\":${{ steps.plan.outputs.exitcode }}}" > result-drift-${{ matrix.terraform }}.json
84+
85+
- name: Upload result artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: drift-results-${{ matrix.terraform }}
89+
path: result-drift-${{ matrix.terraform }}.json
8790

8891
acceptance:
8992
name: "Acceptance Tests (TF ${{ matrix.terraform }})"
@@ -93,12 +96,11 @@ jobs:
9396
max-parallel: 1
9497
fail-fast: false
9598
matrix:
96-
terraform: [
97-
'0.15.5',
98-
'0.14.11',
99-
'1.1.2',
100-
'1.5.3'
101-
]
99+
terraform:
100+
- '0.15.5'
101+
- '0.14.11'
102+
- '1.1.2'
103+
- '1.5.3'
102104
env:
103105
AQUA_URL: ${{ secrets.AQUA_URL }}
104106
AQUA_USER: ${{ secrets.AQUA_USER }}
@@ -108,52 +110,113 @@ jobs:
108110
uses: actions/setup-go@v5
109111
with:
110112
go-version: '1.18'
111-
id: go
112113

113114
- name: Check out repo
114115
uses: actions/checkout@v4
115116

116117
- name: Get dependencies
117-
run: |
118-
go mod download
118+
run: go mod download
119119

120120
- name: Run TF acceptance tests
121121
id: accept_tests
122122
uses: nick-fields/retry@v2
123+
with:
124+
max_attempts: 2
125+
timeout_minutes: 15
126+
command: go test -v -cover ./aquasec/ -timeout 15m
123127
env:
124128
TF_ACC: "1"
125129
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
126130
AQUA_URL: ${{ secrets.AQUA_URL }}
127131
AQUA_USER: ${{ secrets.AQUA_USER }}
128132
AQUA_PASSWORD: ${{ secrets.AQUA_PASSWORD }}
129-
with:
130-
max_attempts: 2
131-
timeout_minutes: 15
132-
command: go test -v -cover ./aquasec/ -timeout 15m
133133

134-
outputs:
135-
accepted: ${{ steps.accept_tests.outcome }}
134+
- name: Write acceptance result file
135+
run: |
136+
result="failure"
137+
if [ "${{ steps.accept_tests.outcome }}" = "success" ]; then
138+
result="success"
139+
fi
140+
echo "{\"version\":\"${{ matrix.terraform }}\",\"result\":\"${result}\"}" > result-acceptance-${{ matrix.terraform }}.json
141+
142+
- name: Upload acceptance result artifact
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: acceptance-results-${{ matrix.terraform }}
146+
path: result-acceptance-${{ matrix.terraform }}.json
136147

137148
notify:
138149
name: "Notify via Power Automate Webhook"
139150
runs-on: ubuntu-latest
140-
needs: [drift, acceptance]
151+
needs:
152+
- drift
153+
- acceptance
141154
if: ${{ always() }}
142155
steps:
143-
- name: Trigger Power Automate Flow
144-
uses: fjogeleit/http-request-action@v1.16.3
156+
- name: Download all drift artifacts
157+
uses: actions/download-artifact@v3
145158
with:
146-
url: ${{ secrets.POWER_AUTOMATE_HOOK_URL }}
147-
method: 'POST'
148-
contentType: 'application/json'
149-
data: |
150-
{
151-
"status": "${{ (needs.drift.result == 'failure' || needs.acceptance.result == 'failure') && 'FAILED' || 'PASSED' }}",
152-
"branch": "main",
153-
"drift_exitcode": "${{ needs.drift.outputs.drifted }}",
154-
"acceptance_outcome": "${{ needs.acceptance.outputs.accepted }}",
155-
"workflow": "${{ github.workflow }}",
156-
"run_id": "${{ github.run_id }}",
157-
"github_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
158-
"tested_versions": ["0.15.5","0.14.11","1.1.2","1.5.3"]
159-
}
159+
path: drift-artifacts
160+
161+
- name: Download all acceptance artifacts
162+
uses: actions/download-artifact@v3
163+
with:
164+
path: acceptance-artifacts
165+
166+
- name: Aggregate results and send webhook
167+
run: |
168+
# build JSON objects
169+
drift_summary="{"
170+
acc_summary="{"
171+
first=true
172+
173+
for file in drift-artifacts/result-drift-*.json; do
174+
version=$(jq -r .version < "$file")
175+
exitcode=$(jq -r .exitcode < "$file")
176+
# interpret exitcode: 0=no drift, 2=drift detected, 1=error
177+
status="unknown"
178+
if [ "$exitcode" -eq 0 ]; then
179+
status="no_drift"
180+
elif [ "$exitcode" -eq 2 ]; then
181+
status="drift_detected"
182+
elif [ "$exitcode" -eq 1 ]; then
183+
status="error"
184+
fi
185+
186+
[ "$first" = false ] && drift_summary+=", "
187+
drift_summary+="\"${version}\": \"${status}\""
188+
189+
first=false
190+
done
191+
drift_summary+="}"
192+
193+
first=true
194+
for file in acceptance-artifacts/result-acceptance-*.json; do
195+
version=$(jq -r .version < "$file")
196+
result=$(jq -r .result < "$file")
197+
198+
[ "$first" = false ] && acc_summary+=", "
199+
acc_summary+="\"${version}\": \"${result}\""
200+
201+
first=false
202+
done
203+
acc_summary+="}"
204+
205+
# send the payload
206+
payload=$(jq -n \
207+
--arg wf "${{ github.workflow }}" \
208+
--arg branch "${{ github.ref_name }}" \
209+
--arg runid "${{ github.run_id }}" \
210+
--arg url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
211+
--argjson tested_versions '["0.15.5","0.14.11","1.1.2","1.5.3"]' \
212+
--argjson drift_summary "$drift_summary" \
213+
--argjson acceptance_summary "$acc_summary" \
214+
'{workflow: $wf, branch: $branch, run_id: $runid, github_url: $url, tested_versions: $tested_versions, drift_summary: $drift_summary, acceptance_summary: $acceptance_summary }')
215+
216+
echo "$payload"
217+
curl -X POST "${{ secrets.POWER_AUTOMATE_HOOK_URL }}" \
218+
-H "Content-Type: application/json" \
219+
-d "$payload"
220+
221+
# you’ll need jq installed; the ubuntu-latest runner includes jq already
222+

aquasec/resource_acknowledge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ resource "aquasec_image" "example_aquasec_image" {
6262
6363
provisioner "local-exec" {
6464
command = <<EOT
65-
sleep 60
65+
sleep 90
6666
EOT
6767
}
6868
}

0 commit comments

Comments
 (0)