Skip to content

Commit 4a6d03a

Browse files
authored
New: [AEA-5667] - Run CloudFormation Guard against Terraform plans (#24)
## Summary - ✨ Now scans Terraform plans using CloudFormation Guard.
1 parent cb3642c commit 4a6d03a

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

.gitallowed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
token: ?"?\$\{\{\s*secrets\.GITHUB_TOKEN\s*\}\}"?
22
.*\.gitallowed.*
3+
id-token: write

.github/workflows/quality-checks.yml

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,6 @@ jobs:
192192
run: |
193193
make check-licenses
194194
195-
- name: Check licenses (Python)
196-
if: steps.check_poetry.outputs.uses_poetry == 'true'
197-
run: |
198-
#!/bin/bash
199-
set -euo pipefail
200-
201-
# Install pip-licenses if not already installed
202-
if ! poetry run pip show pip-licenses > /dev/null 2>&1; then
203-
echo "pip-licenses is not detected. Installing..."
204-
poetry run pip install pip-licenses
205-
fi
206-
207-
# known packages with dual licensing
208-
IGNORE_PACKAGES="PyGithub chardet text-unidecode"
209-
LICENSES=$(poetry run pip-licenses --ignore-packages "${IGNORE_PACKAGES}")
210-
INCOMPATIBLE_LIBS=$(echo "$LICENSES" | grep 'GPL' || true)
211-
212-
if [[ -z $INCOMPATIBLE_LIBS ]]; then
213-
echo "Checked licenses are OK"
214-
exit 0
215-
else
216-
echo "The following libraries were found which are not compatible with this project's license:"
217-
echo "$INCOMPATIBLE_LIBS"
218-
exit 1
219-
fi
220-
221195
- name: Run code lint
222196
run: make lint
223197

@@ -301,7 +275,7 @@ jobs:
301275
declare -a rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar")
302276
for ruleset in "${rulesets[@]}"
303277
do
304-
echo "Checking all templates in cloudformation folder with ruleest $ruleset"
278+
echo "Checking all templates in cloudformation folder with ruleset $ruleset"
305279
306280
~/.guard/bin/cfn-guard validate \
307281
--data cloudformation \
@@ -318,7 +292,7 @@ jobs:
318292
declare -a rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar")
319293
for ruleset in "${rulesets[@]}"
320294
do
321-
echo "Checking all templates in cdk.out folder with ruleest $ruleset"
295+
echo "Checking all templates in cdk.out folder with ruleset $ruleset"
322296
323297
~/.guard/bin/cfn-guard validate \
324298
--data cdk.out \
@@ -327,6 +301,42 @@ jobs:
327301
> "cfn_guard_output/cdk.out_$ruleset.txt"
328302
done
329303
304+
- name: Download terraform plans
305+
uses: actions/download-artifact@v5
306+
with:
307+
pattern: '*_terraform_plan'
308+
path: terraform_plans/
309+
merge-multiple: true
310+
311+
- name: Check terraform plans exist
312+
id: check_terraform_plans
313+
run: |
314+
if [ ! -d terraform_plans ]; then
315+
echo "Terraform plans not present."
316+
echo "terraform_plans_exist=false" >> "$GITHUB_OUTPUT"
317+
else
318+
echo "Terraform plans present:"
319+
ls -l terraform_plans/
320+
echo "terraform_plans_exist=true" >> "$GITHUB_OUTPUT"
321+
fi
322+
323+
- name: Run cfn-guard script for terraform plans
324+
if: steps.check_terraform_plans.outputs.terraform_plans_exist == 'true'
325+
run: |
326+
#!/usr/bin/env bash
327+
328+
declare -a rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar")
329+
for ruleset in "${rulesets[@]}"
330+
do
331+
echo "Checking terraform plans with ruleset $ruleset"
332+
333+
~/.guard/bin/cfn-guard validate \
334+
--data terraform_plans \
335+
--rules "/tmp/ruleset/output/$ruleset.guard" \
336+
--show-summary fail \
337+
> "cfn_guard_output/terraform_plans_$ruleset.txt"
338+
done
339+
330340
- name: Show cfn-guard output
331341
if: failure()
332342
run: find cfn_guard_output -type f -print0 | xargs -0 cat

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A workflow to run the quality checks for EPS repositories. The main element of t
1010
- **Scan git history for secrets**: Scans for secret-like patterns, using https://github.com/NHSDigital/software-engineering-quality-framework/blob/main/tools/nhsd-git-secrets/git-secrets
1111
- **SonarCloud Scan**: Performs code analysis using SonarCloud to detect quality issues and vulnerabilities.
1212
- **Validate CloudFormation Templates** (*Conditional*): If CloudFormation, AWS SAM templates or CDK are present, runs `cfn-lint` (SAM and cloudformation only) and `cfn-guard` to validate templates against AWS best practices and security rules.
13+
- **Validate Terraform Plans** Terraform plans can also be scanned by `cfn-guard` by uploading plans as artefacts in the calling workflow. All Terraform plans must end _terraform_plan and be in json format.
1314
- **CDK Synth** (*Conditional*): Runs `make cdk-synth` if packages/cdk folder exists
1415
- **Check Licenses**: Runs `make check-licenses`.
1516
- **Check Python Licenses** (*Conditional*): If the project uses Poetry, scans Python dependencies for incompatible licenses.

0 commit comments

Comments
 (0)