-
Notifications
You must be signed in to change notification settings - Fork 29
/
tfsec-pipeline.yml
79 lines (70 loc) · 3.15 KB
/
tfsec-pipeline.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
trigger: none
pr: none
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: QualityCheckStage
displayName: Quality Check Stage
jobs:
- job: TFSecJob
displayName: Run TFSec Scan
steps:
# TFSec uses static analysis of Terraform templates to spot potential security issues, and
# checks for violations of AWS, Azure and GCP security best practice recommendations.
# NOTE: To disable a specific check from analysis, include it in the command-line as
# follows: -e GEN001,GCP001,GCP002
# Documentation: https://github.com/tfsec/tfsec
- bash: |
mkdir TFSecReport
docker pull aquasec/tfsec:latest
docker run \
--rm \
--volume "$(System.DefaultWorkingDirectory)/Infrastructure-Source-Code/terraform:/src" \
aquasec/tfsec \
/src \
--format JUnit > $(System.DefaultWorkingDirectory)/TFSecReport/TFSec-Report.xml
docker run \
--rm \
--volume "$(System.DefaultWorkingDirectory)/Infrastructure-Source-Code/terraform:/src" \
aquasec/tfsec \
/src
displayName: TFSec Static Code Analysis
name: TFSecScan
condition: always()
# Publish the TFSec report as an artifact to Azure Pipelines
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: TFSec Report'
condition: succeededOrFailed()
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/TFSecReport'
ArtifactName: TFSecReport
# Publish the results of the TFSec analysis as Test Results to the pipeline
- task: PublishTestResults@2
displayName: Publish TFSecReport Test Results
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit' # Options JUnit, NUnit, VSTest, xUnit, cTest
testResultsFiles: '**/*TFSec-Report.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/TFSecReport'
testRunTitle: TFSecScan(via Docker Image)
mergeTestResults: false
failTaskOnFailedTests: false
publishRunAttachments: true
# Clean up any of the containers / images that were used for quality checks
- bash: |
docker rmi "aquasec/tfsec:latest" -f | true
displayName: 'Remove Terraform Quality Check Docker Images'
condition: always()
# IMPORTANT: The version of TFSec extension (as shown on the Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=AquaSecurityOfficial.tfsec-official),
# is not the correct version to reference/use.
# Instead, please check the AquaSec TFSec Releases page: https://github.com/aquasecurity/tfsec/releases/
# Also, you CANNOT use "latest" as the version number, as the extension will fail to install.
- task: tfsec@1
displayName: TFSecScan (via Extension)
condition: always()
inputs:
debug: true
version: v1.28.1
# args: --workspace my-workspace --config-file ./tfsec.yml
dir: $(System.DefaultWorkingDirectory)/Infrastructure-Source-Code/terraform
publishTestResults: true