-
Notifications
You must be signed in to change notification settings - Fork 6
54 lines (47 loc) · 1.61 KB
/
validate-terraform.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: "TF template tests"
on: [workflow_dispatch, pull_request]
jobs:
ValidateTF:
runs-on: ubuntu-latest
name: "Validation (format & syntax)"
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v4
name: Checkout source code
- uses: hashicorp/setup-terraform@v3
name: Setup Terraform
- name: Initialize and Validate Terraform Modules
run: |
# Find all directories inside the 'aws' directory that contain Terraform files
dirs=$(find . -type f -name "versions.tf" -not -path "*example*" -exec dirname {} \; | sort -u)
for dir in $dirs; do
echo "Running terraform init and validate in directory: $dir"
cd $dir
terraform init -input=false
terraform validate
cd - # Go back to the root directory
done
CHECKOV-SCAN:
runs-on: ubuntu-latest
name: "Security Scan"
defaults:
run:
working-directory: ./
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Checkov
run: pip install checkov
- name: Find and run Checkov on Terraform modules
run: |
dirs=$(find . -type f -name "versions.tf" -not -path "*example*" -exec dirname {} \; | sort -u)
for dir in $dirs; do
echo "Running Checkov in directory: $dir"
checkov --directory $dir --quiet --framework terraform --output_format cli --download_external_modules true
done