-
Notifications
You must be signed in to change notification settings - Fork 34
156 lines (133 loc) · 3.78 KB
/
terraform-checks.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: "Terraform Checks"
on:
push:
branches:
- master
- main
- develop
- "deployment/**"
paths:
- infra/**
pull_request:
branches:
- master
- main
- develop
- "deployment/**"
paths:
- infra/**
jobs:
terraform-CI-checks-staging:
name: "Formatting and validation Checks for Staging"
runs-on: ubuntu-latest
defaults:
run:
working-directory: infra
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }}
- name: Check code formating
id: fmt
run: terraform fmt -check
- name: Initialise modules
id: init
run: terraform init
- name: Validate template
id: validate
run: terraform validate -no-color
terraform-CI-check-production:
name: "Formatting and validation Checks for Production"
runs-on: ubuntu-latest
defaults:
run:
working-directory: infra/production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }}
- name: Check code formating
id: fmt
run: terraform fmt -check
- name: Initialise modules
id: init
run: terraform init
- name: Validate template
id: validate
run: terraform validate -no-color
terrascan-staging:
name: "Terrascan Staging Checks"
runs-on: ubuntu-latest
defaults:
run:
working-directory: infra
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run Terrascan on staging
id: terrascan
uses: tenable/terrascan-action@main
with:
iac_type: "terraform"
iac_dir: "./infra"
iac_version: "v14"
policy_type: "all"
terrascan-production:
name: "Terrascan Production Checks"
runs-on: ubuntu-latest
defaults:
run:
working-directory: infra/production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run Terrascan on production
id: terrascan
uses: tenable/terrascan-action@main
with:
iac_type: "terraform"
iac_dir: "./infra/production"
iac_version: "v14"
policy_type: "all"
checkov-staging:
runs-on: ubuntu-latest
name: "Checkov Staging Checks"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkov GitHub Action
uses: bridgecrewio/checkov-action@v12
with:
directory: infra/
output_format: cli,sarif
output_file_path: console,results.sarif
checkov-production:
runs-on: ubuntu-latest
permissions:
security-events: write
name: "Checkov Production Checks"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkov GitHub Action
uses: bridgecrewio/checkov-action@v12
with:
directory: infra/production/
output_format: cli,sarif
output_file_path: console,results.sarif
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
# Results are generated only on a success or failure
# this is required since GitHub by default won't run the next step
# when the previous one has failed. Security checks that do not pass will 'fail'.
# An alternative is to add `continue-on-error: true` to the previous step
# Or 'soft_fail: true' to checkov.
if: success() || failure()
with:
sarif_file: results.sarif