1+ name : Terraform Validate
2+
3+ on :
4+ push :
5+ branches : [dev, main, master]
6+ pull_request :
7+ branches : [main, master]
8+
9+ env :
10+ TF_VERSION : " 1.5.0"
11+
12+ jobs :
13+ validate :
14+ name : Validate Terraform
15+ runs-on : ubuntu-latest
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+
21+ - name : Setup Terraform
22+ uses : hashicorp/setup-terraform@v3
23+ with :
24+ terraform_version : ${{ env.TF_VERSION }}
25+
26+ - name : Terraform Format Check
27+ id : fmt
28+ run : terraform fmt -check -recursive
29+ continue-on-error : true
30+
31+ - name : Create dummy tfvars for validation
32+ run : |
33+ cat > terraform.tfvars <<EOF
34+ telegram_token = "dummy-token-for-validation"
35+ lab_role_arn = "arn:aws:iam::123456789012:role/LabRole"
36+ environment = "dev"
37+ EOF
38+
39+ - name : Create dummy package directory
40+ run : |
41+ mkdir -p package
42+ cp handler.py package/
43+ touch package/__init__.py
44+
45+ - name : Terraform Init
46+ id : init
47+ run : terraform init -backend=false
48+
49+ - name : Terraform Validate
50+ id : validate
51+ run : terraform validate
52+
53+ - name : Post Validation Status
54+ if : github.event_name == 'pull_request'
55+ uses : actions/github-script@v7
56+ with :
57+ script : |
58+ const output = `#### Terraform Format 🖌 \`${{ steps.fmt.outcome }}\`
59+ #### Terraform Init ⚙️ \`${{ steps.init.outcome }}\`
60+ #### Terraform Validate 🤖 \`${{ steps.validate.outcome }}\`
61+
62+ *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
63+
64+ github.rest.issues.createComment({
65+ issue_number: context.issue.number,
66+ owner: context.repo.owner,
67+ repo: context.repo.repo,
68+ body: output
69+ })
70+
71+ lint :
72+ name : Lint Python
73+ runs-on : ubuntu-latest
74+
75+ steps :
76+ - name : Checkout code
77+ uses : actions/checkout@v4
78+
79+ - name : Setup Python
80+ uses : actions/setup-python@v5
81+ with :
82+ python-version : " 3.9"
83+
84+ - name : Install dependencies
85+ run : |
86+ python -m pip install --upgrade pip
87+ pip install flake8
88+
89+ - name : Lint with flake8
90+ run : |
91+ # Stop build if there are Python syntax errors or undefined names
92+ flake8 handler.py --count --select=E9,F63,F7,F82 --show-source --statistics
93+ # Exit-zero treats all errors as warnings
94+ flake8 handler.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
95+
96+ security :
97+ name : Security Scan
98+ runs-on : ubuntu-latest
99+
100+ steps :
101+ - name : Checkout code
102+ uses : actions/checkout@v4
103+
104+ - name : Run Checkov (Terraform Security)
105+ uses : bridgecrewio/checkov-action@v12
106+ with :
107+ directory : .
108+ framework : terraform
109+ soft_fail : true
110+ output_format : cli
0 commit comments