Skip to content

Commit ce11b07

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 ce11b07

File tree

2 files changed

+125
-48
lines changed

2 files changed

+125
-48
lines changed

.github/workflows/nightly.yml

Lines changed: 123 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,26 @@ 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+
version="${{ matrix.terraform }}"
84+
exitcode="${{ steps.plan.outputs.exitcode }}"
85+
if [ -z "$exitcode" ]; then
86+
exitcode=??? # choose a default, e.g. 99 for unknown
87+
fi
88+
echo "{\"version\":\"${{ matrix.terraform }}\",\"exitcode\":${{ steps.plan.outputs.exitcode }}}" > result-drift-${{ matrix.terraform }}.json
89+
90+
- name: Upload result artifact
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: drift-results-${{ matrix.terraform }}
94+
path: result-drift-${{ matrix.terraform }}.json
95+
if-no-files-found: error
8796

8897
acceptance:
8998
name: "Acceptance Tests (TF ${{ matrix.terraform }})"
@@ -93,12 +102,11 @@ jobs:
93102
max-parallel: 1
94103
fail-fast: false
95104
matrix:
96-
terraform: [
97-
'0.15.5',
98-
'0.14.11',
99-
'1.1.2',
100-
'1.5.3'
101-
]
105+
terraform:
106+
- '0.15.5'
107+
- '0.14.11'
108+
- '1.1.2'
109+
- '1.5.3'
102110
env:
103111
AQUA_URL: ${{ secrets.AQUA_URL }}
104112
AQUA_USER: ${{ secrets.AQUA_USER }}
@@ -108,52 +116,120 @@ jobs:
108116
uses: actions/setup-go@v5
109117
with:
110118
go-version: '1.18'
111-
id: go
112119

113120
- name: Check out repo
114121
uses: actions/checkout@v4
115122

116123
- name: Get dependencies
117-
run: |
118-
go mod download
124+
run: go mod download
119125

120126
- name: Run TF acceptance tests
121127
id: accept_tests
122128
uses: nick-fields/retry@v2
129+
with:
130+
max_attempts: 2
131+
timeout_minutes: 15
132+
command: go test -v -cover ./aquasec/ -timeout 15m
123133
env:
124134
TF_ACC: "1"
125135
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
126136
AQUA_URL: ${{ secrets.AQUA_URL }}
127137
AQUA_USER: ${{ secrets.AQUA_USER }}
128138
AQUA_PASSWORD: ${{ secrets.AQUA_PASSWORD }}
129-
with:
130-
max_attempts: 2
131-
timeout_minutes: 15
132-
command: go test -v -cover ./aquasec/ -timeout 15m
133139

134-
outputs:
135-
accepted: ${{ steps.accept_tests.outcome }}
140+
- name: Write acceptance result file
141+
run: |
142+
version="${{ matrix.terraform }}"
143+
outcome="${{ steps.accept_tests.outcome }}"
144+
# If outcome is empty or weird, default to "unknown"
145+
if [ -z "$outcome" ]; then
146+
outcome="unknown"
147+
fi
148+
result="failure"
149+
if [ "${{ steps.accept_tests.outcome }}" = "success" ]; then
150+
result="success"
151+
fi
152+
echo "{\"version\":\"${{ matrix.terraform }}\",\"result\":\"${result}\"}" > result-acceptance-${{ matrix.terraform }}.json
153+
154+
- name: Upload acceptance result artifact
155+
uses: actions/upload-artifact@v4
156+
with:
157+
name: acceptance-results-${{ matrix.terraform }}
158+
path: result-acceptance-${{ matrix.terraform }}.json
159+
if-no-files-found: error
136160

137161
notify:
138162
name: "Notify via Power Automate Webhook"
139163
runs-on: ubuntu-latest
140-
needs: [drift, acceptance]
164+
needs:
165+
- drift
166+
- acceptance
141167
if: ${{ always() }}
142168
steps:
143-
- name: Trigger Power Automate Flow
144-
uses: fjogeleit/http-request-action@v1.16.3
169+
- name: Download all drift artifacts
170+
uses: actions/download-artifact@v4
145171
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-
}
172+
path: drift-artifacts
173+
174+
- name: Download all acceptance artifacts
175+
uses: actions/download-artifact@v4
176+
with:
177+
path: acceptance-artifacts
178+
179+
- name: Aggregate results and send webhook
180+
run: |
181+
# build JSON objects
182+
drift_summary="{"
183+
acc_summary="{"
184+
first=true
185+
186+
for file in drift-artifacts/result-drift-*.json; do
187+
version=$(jq -r .version < "$file")
188+
exitcode=$(jq -r .exitcode < "$file")
189+
# interpret exitcode: 0=no drift, 2=drift detected, 1=error
190+
status="unknown"
191+
if [ "$exitcode" -eq 0 ]; then
192+
status="no_drift"
193+
elif [ "$exitcode" -eq 2 ]; then
194+
status="drift_detected"
195+
elif [ "$exitcode" -eq 1 ]; then
196+
status="error"
197+
fi
198+
199+
[ "$first" = false ] && drift_summary+=", "
200+
drift_summary+="\"${version}\": \"${status}\""
201+
202+
first=false
203+
done
204+
drift_summary+="}"
205+
206+
first=true
207+
for file in acceptance-artifacts/result-acceptance-*.json; do
208+
version=$(jq -r .version < "$file")
209+
result=$(jq -r .result < "$file")
210+
211+
[ "$first" = false ] && acc_summary+=", "
212+
acc_summary+="\"${version}\": \"${result}\""
213+
214+
first=false
215+
done
216+
acc_summary+="}"
217+
218+
# send the payload
219+
payload=$(jq -n \
220+
--arg wf "${{ github.workflow }}" \
221+
--arg branch "${{ github.ref_name }}" \
222+
--arg runid "${{ github.run_id }}" \
223+
--arg url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
224+
--argjson tested_versions '["0.15.5","0.14.11","1.1.2","1.5.3"]' \
225+
--argjson drift_summary "$drift_summary" \
226+
--argjson acceptance_summary "$acc_summary" \
227+
'{workflow: $wf, branch: $branch, run_id: $runid, github_url: $url, tested_versions: $tested_versions, drift_summary: $drift_summary, acceptance_summary: $acceptance_summary }')
228+
229+
echo "$payload"
230+
curl -X POST "${{ secrets.POWER_AUTOMATE_HOOK_URL }}" \
231+
-H "Content-Type: application/json" \
232+
-d "$payload"
233+
234+
# you’ll need jq installed; the ubuntu-latest runner includes jq already
235+

aquasec/resource_acknowledge_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
func TestAquasecAcknowledge(t *testing.T) {
12+
t.Parallel()
1213
// Define the issue to be acknowledged
1314
issue := map[string]interface{}{
1415
"docker_id": "",
@@ -62,7 +63,7 @@ resource "aquasec_image" "example_aquasec_image" {
6263
6364
provisioner "local-exec" {
6465
command = <<EOT
65-
sleep 60
66+
sleep 120
6667
EOT
6768
}
6869
}

0 commit comments

Comments
 (0)