Skip to content

Commit 45abd79

Browse files
CCM-10921: Add Lambda Boilerplate
1 parent 356d4c4 commit 45abd79

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
name: "TFSec Scan"
2-
description: "Scan HCL using TFSec"
1+
name: "Trivy Scan"
32
runs:
43
using: "composite"
54
steps:
6-
- name: "TFSec Scan - Components"
5+
- name: "Trivy Terraform IAC Scan"
76
shell: bash
87
run: |
98
components_exit_code=0
109
modules_exit_code=0
1110
12-
./scripts/terraform/tfsec.sh ./infrastructure/terraform/components || components_exit_code=$?
13-
./scripts/terraform/tfsec.sh ./infrastructure/terraform/modules || modules_exit_code=$?
11+
./scripts/terraform/trivy.sh ./infrastructure/terraform/components || components_exit_code=$?
12+
./scripts/terraform/trivy.sh ./infrastructure/terraform/modules || modules_exit_code=$?
1413
1514
if [ $components_exit_code -ne 0 ] || [ $modules_exit_code -ne 0 ]; then
16-
echo "One or more TFSec scans failed."
15+
echo "Trivy misconfigurations detected."
1716
exit 1
1817
fi

.github/workflows/stage-1-commit.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ jobs:
135135
uses: actions/checkout@v4
136136
- name: "Lint Terraform"
137137
uses: ./.github/actions/lint-terraform
138-
tfsec:
139-
name: "TFSec Scan"
138+
trivy:
139+
name: "Trivy Scan"
140140
runs-on: ubuntu-latest
141141
timeout-minutes: 5
142142
needs: detect-terraform-changes
@@ -148,8 +148,8 @@ jobs:
148148
uses: asdf-vm/actions/setup@v3
149149
- name: "Perform Setup"
150150
uses: ./.github/actions/setup
151-
- name: "TFSec Scan"
152-
uses: ./.github/actions/tfsec
151+
- name: "Trivy Scan"
152+
uses: ./.github/actions/trivy
153153
count-lines-of-code:
154154
name: "Count lines of code"
155155
runs-on: ubuntu-latest

.tool-versions

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pre-commit 3.6.0
77
python 3.13.2
88
terraform 1.9.2
99
terraform-docs 0.19.0
10-
tfsec 1.28.10
1110
trivy 0.61.0
1211
vale 3.6.0
1312

infrastructure/terraform/components/examplecomponent/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ No requirements.
1313
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"examplecomponent"` | no |
1414
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
1515
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
16+
| <a name="input_force_lambda_code_deploy"></a> [force\_lambda\_code\_deploy](#input\_force\_lambda\_code\_deploy) | If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development | `bool` | `false` | no |
1617
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
1718
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
1819
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |

infrastructure/terraform/components/examplecomponent/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ variable "log_retention_in_days" {
5656
description = "The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite"
5757
default = 0
5858
}
59+
60+
variable "force_lambda_code_deploy" {
61+
type = bool
62+
description = "If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development"
63+
default = false
64+
}
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -euo pipefail
99
# Run tfsec for security checks on Terraform code.
1010
#
1111
# Usage:
12-
# $ ./tfsec.sh [directory]
12+
# $ ./trivy.sh [directory]
1313
# ==============================================================================
1414

1515
function main() {
@@ -18,68 +18,63 @@ function main() {
1818

1919
local dir_to_scan=${1:-.}
2020

21-
if command -v tfsec > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
21+
if command -v trivy > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
2222
# shellcheck disable=SC2154
23-
run-tfsec-natively "$dir_to_scan"
23+
run-trivy-natively "$dir_to_scan"
2424
else
25-
run-tfsec-in-docker "$dir_to_scan"
25+
run-trivy-in-docker "$dir_to_scan"
2626
fi
2727
}
2828

29-
# Run tfsec on the specified directory.
29+
# Run trivy on the specified directory.
3030
# Arguments:
3131
# $1 - Directory to scan
32-
function run-tfsec-natively() {
32+
function run-trivy-natively() {
3333

3434
local dir_to_scan="$1"
3535

36-
echo "TFSec found locally, running natively"
36+
echo "Trivy found locally, running natively"
3737

38-
echo "Running TFSec on directory: $dir_to_scan"
39-
tfsec \
40-
--force-all-dirs \
41-
--exclude-downloaded-modules \
42-
--config-file scripts/config/tfsec.yaml \
43-
--format text \
44-
"$dir_to_scan"
38+
echo "Running Trivy on directory: $dir_to_scan"
39+
trivy config \
40+
--config scripts/config/trivy.yaml \
41+
--tf-exclude-downloaded-modules \
42+
"${dir_to_scan}"
4543

46-
check-tfsec-status
44+
check-trivy-status
4745
}
4846

4947
# Check the exit status of tfsec.
50-
function check-tfsec-status() {
48+
function check-trivy-status() {
5149

5250
if [ $? -eq 0 ]; then
53-
echo "TFSec completed successfully."
51+
echo "Trivy completed successfully."
5452
else
55-
echo "TFSec found issues."
53+
echo "Trivy found issues."
5654
exit 1
5755
fi
5856
}
5957

60-
function run-tfsec-in-docker() {
58+
function run-trivy-in-docker() {
6159

6260
# shellcheck disable=SC1091
6361
source ./scripts/docker/docker.lib.sh
6462
local dir_to_scan="$1"
6563

6664
# shellcheck disable=SC2155
67-
local image=$(name=aquasec/tfsec docker-get-image-version-and-pull)
65+
local image=$(name=aquasec/trivy docker-get-image-version-and-pull)
6866
# shellcheck disable=SC2086
69-
echo "TFSec not found locally, running in Docker Container"
70-
echo "Running TFSec on directory: $dir_to_scan"
67+
echo "Trivy not found locally, running in Docker Container"
68+
echo "Running Trivy on directory: $dir_to_scan"
7169
docker run --rm --platform linux/amd64 \
7270
--volume "$PWD":/workdir \
7371
--workdir /workdir \
7472
"$image" \
75-
--concise-output \
76-
--force-all-dirs \
77-
--exclude-downloaded-modules \
78-
--config-file scripts/config/tfsec.yaml \
79-
--format text \
80-
--soft-fail \
81-
"$dir_to_scan"
82-
check-tfsec-status
73+
config \
74+
--config scripts/config/trivy.yaml \
75+
--tf-exclude-downloaded-modules \
76+
"${dir_to_scan}"
77+
check-trivy-status
8378
}
8479
# ==============================================================================
8580

0 commit comments

Comments
 (0)