Skip to content

Commit b366bfc

Browse files
author
Wellington Gonzalez
committed
chore(ci): add ENVIRONMENT env var to docker execution step
1 parent 0633da8 commit b366bfc

2 files changed

Lines changed: 72 additions & 18 deletions

File tree

.github/workflows/terraform-aws-security-analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
-e GEMINI_API_KEY="$GEMINI_API_KEY" \
8585
-e BRANCH_NAME="$BRANCH_NAME" \
8686
-e RUN_TIMESTAMP="$RUN_TIMESTAMP" \
87+
-e ENVIRONMENT="develop" \
8788
-v "$GITHUB_WORKSPACE:/repo" \
8889
-v "$GITHUB_WORKSPACE/reports_output:/app/reports_output" \
8990
-w /repo \

README.md

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,86 @@ on:
157157
- 'terraform/**'
158158

159159
jobs:
160-
analyze:
160+
terraform_plan:
161161
runs-on: ubuntu-latest
162+
163+
services:
164+
localstack:
165+
image: localstack/localstack:latest
166+
ports:
167+
- 4566:4566
168+
env:
169+
SERVICES: s3,iam,ec2,sts,logs,events,cloudwatch,lambda,apigateway,ecs,elasticloadbalancing
170+
DEBUG: "0"
171+
172+
steps:
173+
- uses: actions/checkout@v4
174+
175+
- uses: hashicorp/setup-terraform@v3
176+
177+
- name: Terraform init/validate/plan against LocalStack
178+
working-directory: ${{ inputs.terraform_dir }}
179+
env:
180+
AWS_ACCESS_KEY_ID: test
181+
AWS_SECRET_ACCESS_KEY: test
182+
AWS_DEFAULT_REGION: us-east-1
183+
AWS_ENDPOINT_URL: http://localhost:4566
184+
AWS_EC2_METADATA_DISABLED: "true"
185+
186+
run: |
187+
terraform init -input=false -no-color -backend=false
188+
terraform validate -no-color
189+
terraform plan -input=false -no-color -refresh=false -out=tfplan.binary
190+
terraform show -json tfplan.binary > plan.json
191+
192+
- name: Upload plan.json artifact
193+
uses: actions/upload-artifact@v4
194+
with:
195+
name: terraform-plan-json
196+
path: ${{ inputs.terraform_dir }}/plan.json
197+
if-no-files-found: error
198+
199+
analyze_plan:
200+
runs-on: ubuntu-latest
201+
needs: terraform_plan
202+
162203
steps:
163204
- uses: actions/checkout@v4
164-
- name: Set up Terraform
165-
uses: hashicorp/setup-terraform@v3
205+
206+
- uses: actions/download-artifact@v4
166207
with:
167-
terraform_version: "1.6.0"
168-
- name: Generate Plan
208+
name: terraform-plan-json
209+
path: artifacts_in
210+
211+
- run: mkdir -p reports_output
212+
213+
- name: Prepare execution metadata
214+
id: metadata
169215
run: |
170-
cd terraform/examples/your-example/env/dev
171-
terraform init
172-
terraform plan -out=tfplan.binary
173-
terraform show -json tfplan.binary > ../../../../plans/tfplan.json
174-
- name: Run Security Analyzer
216+
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV
217+
echo "RUN_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
218+
219+
- name: Run analyzer (Docker)
220+
env:
221+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
175222
run: |
176-
docker build -t analyzer .
177223
docker run --rm \
178-
-e GEMINI_API_KEY="${{ secrets.GEMINI_API_KEY }}" \
179-
-v "$(pwd):/app" \
180-
analyzer \
181-
plans/tfplan.json
182-
- name: Upload Report
224+
-e GEMINI_API_KEY="$GEMINI_API_KEY" \
225+
-e BRANCH_NAME="$BRANCH_NAME" \
226+
-e RUN_TIMESTAMP="$RUN_TIMESTAMP" \
227+
-e ENVIRONMENT="develop" \
228+
-v "$GITHUB_WORKSPACE:/repo" \
229+
-v "$GITHUB_WORKSPACE/reports_output:/app/reports_output" \
230+
-w /repo \
231+
wellingtoong/cloud-security-analyzer:1.0.1 \
232+
artifacts_in/plan.json
233+
234+
- name: Upload HTML report artifact
183235
uses: actions/upload-artifact@v4
184236
with:
185-
name: security-report
186-
path: reports_output/
237+
name: terraform-security-report-html
238+
path: reports_output/terraform_security_report.html
239+
if-no-files-found: error
187240
```
188241
189242
This pipeline generates plans, runs analysis, and publishes HTML reports as artifacts for review.

0 commit comments

Comments
 (0)