forked from diggerhq/digger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
330 lines (312 loc) · 11.9 KB
/
action.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
name: run-digger
description: Manage terraform collaboration
author: Digger
inputs:
setup-aws:
description: Setup AWS
required: false
default: 'false'
aws-access-key-id:
description: AWS access key id
required: false
aws-secret-access-key:
description: AWS secret access key
required: false
aws-role-to-assume:
description: ARN of AWS IAM role to assume using OIDC
required: false
aws-region:
description: AWS region
required: false
default: us-east-1
setup-google-cloud:
description: Setup google cloud
required: false
default: 'false'
google-auth-credentials:
description: Service account key used got Google auth (mutually exclusive with 'google-workload-identity-provider' input)
required: false
google-workload-identity-provider:
description: Workload identity provider to be used for Google OIDC auth (mutually exclusive with 'google-auth-credentials' input)
required: false
google-workload-identity-provider-audience:
description: "'audience' parameter configured in Google's Workload Identity Provider (if specified). To be used when the 'google-workload-identity-provider' input is specified"
required: false
google-service-account:
description: Service account to be used when the 'google-workload-identity-provider' input is specified)
required: false
setup-azure:
description: Setup Azure
required: false
default: 'false'
azure-client-id:
description: Azure Client ID to be used for Azure OIDC auth
required: false
azure-tenant-id:
description: AzureAD ID of the organization you are using
required: false
azure-subscription-id:
description: Subscription ID of you are using
required: false
setup-terragrunt:
description: Setup terragrunt
required: false
default: 'false'
setup-opentofu:
description: Setup OpenToFu
required: false
default: 'false'
terragrunt-version:
description: Terragrunt version
required: false
default: v0.55.5
opentofu-version:
description: OpenTofu version
required: false
default: v1.6.1
setup-terraform:
description: Setup terraform
required: false
default: 'false'
terraform-version:
description: Terraform version
required: false
default: v1.5.5
configure-checkout:
description: Configure checkout. Beware that this will overwrite any changes in the working directory
required: false
default: 'true'
upload-plan-destination:
description: Destination to upload the plan to. gcp, github and aws are currently supported.
required: false
upload-plan-destination-s3-bucket:
description: Name of the destination bucket for AWS S3. Should be provided if destination == aws
required: false
upload-plan-destination-gcp-bucket:
description: Name of the destination bucket for a GCP bucket. Should be provided if destination == gcp
required: false
setup-checkov:
description: Setup Checkov
required: false
default: 'false'
checkov-version:
description: Checkov version
required: false
default: '3.2.22'
disable-locking:
description: Disable locking
required: false
default: 'false'
digger-filename:
description: Alternative Digger configuration file name
required: false
digger-token:
description: Digger token
required: false
digger-hostname:
description: Digger hostname
required: false
default: 'https://cloud.digger.dev'
digger-organisation:
description: The name of your digger organisation
required: false
setup-tfenv:
description: Setup tfenv
required: false
default: 'false'
post-plans-as-one-comment:
description: Post plans as one comment
required: false
default: 'false'
reporting-strategy:
description: 'comments_per_run or latest_run_comment, anything else will default to original behavior of multiple comments'
required: false
default: 'comments_per_run'
mode:
description: 'manual, drift-detection or otherwise'
required: false
default: ''
no-backend:
description: 'run cli-only, without an orchestrator backend'
required: false
default: 'false'
command:
description: 'digger plan or digger apply in case of manual mode'
required: false
default: ''
project:
description: 'project name for digger to run in case of manual mode'
required: false
default: ''
drift-detection-slack-notification-url:
description: 'drift-detection slack drift url'
required: false
default: ''
outputs:
output:
value: ${{ steps.digger.outputs.output }}
description: The terraform output
runs:
using: composite
steps:
- name: digger run ${{github.event.inputs.id}}
run: echo digger run ${{ inputs.id }}
shell: bash
- name: Validate Input Configuration for Google
run: |
if [[ -z ${{ toJSON(inputs.google-auth-credentials) }} && -z "${{ inputs.google-workload-identity-provider }}" ]]; then
echo "Either 'google-auth-credentials' or 'google-workload-identity-provider' input must be specified with 'setup-google-cloud'"
elif [[ ! -z "${{ inputs.google-workload-identity-provider }}" && -z "${{ inputs.google-service-account }}" ]]; then
echo "'google-service-account' input must be specified with 'google-workload-identity-provider'"
else
exit 0
fi
exit 1
shell: bash
if: inputs.setup-google-cloud == 'true'
- uses: actions/checkout@v4
with:
clean: false
ref: refs/pull/${{ github.event.issue.number }}/merge
if: ${{ github.event_name == 'issue_comment' && inputs.configure-checkout == 'true' }}
- uses: actions/checkout@v4
with:
clean: false
if: ${{ github.event_name != 'issue_comment' && inputs.configure-checkout == 'true' }}
- name: Set up Google Auth Using A Service Account Key
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ inputs.google-auth-credentials }}'
if: ${{ inputs.setup-google-cloud == 'true' && inputs.google-auth-credentials != '' }}
- name: Set up Google Auth Using Workload Identity Federation
uses: google-github-actions/auth@v2
with:
token_format: access_token
service_account: ${{ inputs.google-service-account }}
workload_identity_provider: ${{ inputs.google-workload-identity-provider }}
audience: ${{ inputs.google-workload-identity-provider-audience }}
if: ${{ inputs.setup-google-cloud == 'true' && inputs.google-workload-identity-provider != '' }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
if: inputs.setup-google-cloud == 'true'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ inputs.aws-access-key-id }}
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
aws-region: ${{ inputs.aws-region }}
if: ${{ inputs.setup-aws == 'true' && inputs.aws-role-to-assume == '' }}
- name: Configure OIDC AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.aws-role-to-assume }}
aws-region: ${{ inputs.aws-region }}
if: ${{ inputs.setup-aws == 'true' && inputs.aws-role-to-assume != '' }}
- name: Configure OIDC Azure credentials
uses: azure/[email protected]
with:
client-id: ${{ inputs.azure-client-id }}
tenant-id: ${{ inputs.azure-tenant-id }}
subscription-id: ${{ inputs.azure-subscription-id }}
if: ${{ inputs.setup-azure == 'true' && inputs.azure-client-id != '' }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform-version }}
terraform_wrapper: false
if: inputs.setup-terraform == 'true'
- name: Setup tfenv
uses: rhythmictech/[email protected]
if: inputs.setup-tfenv == 'true'
- name: Setup Terragrunt
uses: autero1/[email protected]
with:
terragrunt-version: ${{ inputs.terragrunt-version }}
if: inputs.setup-terragrunt == 'true'
- name: Setup OpenTofu
uses: opentofu/[email protected]
with:
tofu_version: ${{ inputs.opentofu-version }}
if: inputs.setup-opentofu == 'true'
- name: Setup Checkov
run: |
python3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install --upgrade setuptools
pip3 install -U checkov==${{ inputs.checkov-version }}
shell: bash
if: inputs.setup-checkov == 'true'
- name: setup go
uses: actions/setup-go@v5
with:
go-version: '^1.21.1'
if: ${{ !startsWith(github.action_ref, 'v') }}
- name: Adding required env vars for next step
uses: actions/github-script@v7
env:
github-token: $GITHUB_TOKEN
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env['ACTIONS_CACHE_URL'])
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN'])
core.exportVariable('ACTIONS_RUNTIME_URL', process.env['ACTIONS_RUNTIME_URL'])
- name: build and run digger
if: ${{ !startsWith(github.action_ref, 'v') }}
shell: bash
env:
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
GOOGLE_STORAGE_BUCKET: ${{ inputs.upload-plan-destination-gcp-bucket }}
AWS_S3_BUCKET: ${{ inputs.upload-plan-destination-s3-bucket }}
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
DIGGER_TOKEN: ${{ inputs.digger-token }}
DIGGER_ORGANISATION: ${{ inputs.digger-organisation }}
DIGGER_HOSTNAME: ${{ inputs.digger-hostname }}
DIGGER_FILENAME: ${{ inputs.digger-filename }}
ACCUMULATE_PLANS: ${{ inputs.post-plans-as-one-comment == 'true' }}
REPORTING_STRATEGY: ${{ inputs.reporting-strategy }}
INPUT_DIGGER_PROJECT: ${{ inputs.project }}
INPUT_DIGGER_MODE: ${{ inputs.mode }}
INPUT_DIGGER_COMMAND: ${{ inputs.command }}
INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }}
NO_BACKEND: ${{ inputs.no-backend }}
DEBUG: 'true'
run: |
cd $GITHUB_ACTION_PATH/cli
go build -o digger ./cmd/digger
chmod +x digger
PATH=$PATH:$(pwd)
cd $GITHUB_WORKSPACE
digger
- name: run digger
if: ${{ startsWith(github.action_ref, 'v') }}
env:
actionref: ${{ github.action_ref }}
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
GOOGLE_STORAGE_BUCKET: ${{ inputs.upload-plan-destination-gcp-bucket }}
AWS_S3_BUCKET: ${{ inputs.upload-plan-destination-s3-bucket }}
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
DIGGER_TOKEN: ${{ inputs.digger-token }}
DIGGER_ORGANISATION: ${{ inputs.digger-organisation }}
DIGGER_HOSTNAME: ${{ inputs.digger-hostname }}
DIGGER_FILENAME: ${{ inputs.digger-filename }}
ACCUMULATE_PLANS: ${{ inputs.post-plans-as-one-comment == 'true' }}
REPORTING_STRATEGY: ${{ inputs.reporting-strategy }}
INPUT_DIGGER_PROJECT: ${{ inputs.project }}
INPUT_DIGGER_MODE: ${{ inputs.mode }}
INPUT_DIGGER_COMMAND: ${{ inputs.command }}
INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }}
NO_BACKEND: ${{ inputs.no-backend }}
id: digger
shell: bash
run: |
curl -sL https://github.com/diggerhq/digger/releases/download/${actionref}/digger-cli-${{ runner.os }}-${{ runner.arch }} -o digger
chmod +x digger
PATH=$PATH:$(pwd)
cd $GITHUB_WORKSPACE
digger
branding:
icon: globe
color: purple