Skip to content

Commit

Permalink
CCM-6245: TFSec Scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesthompson26-nhs committed Aug 16, 2024
1 parent 437e1a4 commit d9f11fd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/actions/tfsec/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "TFSec Scan"
description: "Scan HCL using TFSec"
inputs:
root-modules:
description: "Comma separated list of root module directories to validate, content of the 'infrastructure/environments' is checked by default"
required: false
runs:
using: "composite"
steps:
- name: "TFSec Scan Components"
shell: bash
run: |
for component in $(find infrastructure/terraform/components -mindepth 1 -type d); do
scripts/terraform/tfsec.sh $component
done
- name: "TFSec Scan Modules"
shell: bash
run: |
for module in $(find infrastructure/terraform/modules -mindepth 1 -type d); do
scripts/terraform/tfsec.sh $module
done
9 changes: 9 additions & 0 deletions .github/workflows/stage-1-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ jobs:
uses: actions/checkout@v4
- name: "Lint Terraform"
uses: ./.github/actions/lint-terraform
tfsec:
name: "TFSec Scan"
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Lint Terraform"
uses: ./.github/actions/tfsec
count-lines-of-code:
name: "Count lines of code"
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ terraform 1.9.1
pre-commit 3.6.0
nodejs 18.18.2
gitleaks 8.18.4
tfsec 1.28.10

# ==============================================================================
# The section below is reserved for Docker image versions.
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"**/CVS": true,
"**/Thumbs.db": true,
".devcontainer": true,
".github": true,
".vscode": false
}
}
1 change: 1 addition & 0 deletions scripts/config/tfsec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minimum_severity: MEDIUM
33 changes: 33 additions & 0 deletions scripts/terraform/tfsec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Check if tfsec is installed
if ! command -v tfsec &> /dev/null; then
echo "tfsec could not be found, please install it first."
exit 1
fi

# Check if a directory was passed as an argument
if [ "$#" -eq 1 ]; then
DIR_TO_SCAN="$1"
elif [ "$#" -gt 1 ]; then
echo "Usage: $0 [directory]"
exit 1
fi

# Run tfsec
echo "Running tfsec on directory: $DIR_TO_SCAN"
tfsec \
--concise-output \
--force-all-dirs \
--exclude-downloaded-modules \
--config-file ../config/tfsec.yaml
"$DIR_TO_SCAN"


# Check the exit status of tfsec
if [ $? -eq 0 ]; then
echo "tfsec completed successfully."
else
echo "tfsec found issues."
exit 1
fi

0 comments on commit d9f11fd

Please sign in to comment.