-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
196 lines (164 loc) · 6.6 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
name: 'Terraform Plan for AZURE'
description: 'Terraform plan with AzureRM backend - uploads plan as workflow artifact (Used with: `Pwd9000-ML/terraform-azurerm-apply`)'
inputs:
path:
description: '(Optional) Specifies the path of the root terraform module.'
required: false
type: string
default: .
plan_mode:
description: '(Optional) Specify plan mode. Valid options are "deploy" or "destroy". Default=deploy.'
required: false
type: string
default: deploy
tf_version:
description: '(Optional) Specifies version of Terraform to use. e.g: 1.1.0 Default=latest.'
required: false
type: string
default: latest
tf_vars_file:
description: '(Required) Specifies the Terraform TFVARS file relevant to module path.'
required: true
type: string
tf_key:
description: '(Required) Specifies the Terraform state file name for this plan.'
required: true
type: string
az_resource_group:
description: '(Required) Specifies the Azure Resource Group where the backend storage account is hosted.'
required: true
type: string
az_storage_acc:
description: '(Required) Specifies the Azure Storage Account where the backend state is hosted.'
required: true
type: string
az_container_name:
description: '(Required) Specifies the Azure Storage account container where backend Terraform state is hosted.'
required: true
type: string
enable_TFSEC:
description: '(Optional) Enables TFSEC IaC scans and code quality checks on Terraform configurations'
required: false
type: boolean
default: false
arm_client_id:
description: 'Specifies the Azure ARM CLIENT ID.'
required: true
arm_client_secret:
description: 'Specifies the Azure ARM CLIENT SECRET.'
required: true
arm_subscription_id:
description: 'Specifies the Azure ARM SUBSCRIPTION ID.'
required: true
arm_tenant_id:
description: 'Specifies the Azure ARM TENANT ID.'
required: true
github_token:
description: 'Specify a valid GITHUB TOKEN.'
required: true
# https://actions-cool.github.io/github-action-branding/
branding:
icon: 'align-left'
color: 'blue'
runs:
using: "composite"
steps:
- name: Set Environment VARS
shell: bash
id: vars
run: |
echo "ARM_CLIENT_ID=${{ inputs.arm_client_id }}" >> $GITHUB_ENV
echo "ARM_CLIENT_SECRET=${{ inputs.arm_client_secret }}" >> $GITHUB_ENV
echo "ARM_SUBSCRIPTION_ID=${{ inputs.arm_subscription_id }}" >> $GITHUB_ENV
echo "ARM_TENANT_ID=${{ inputs.arm_tenant_id }}" >> $GITHUB_ENV
echo "GITHUB_TOKEN=${{ inputs.github_token }}" >> $GITHUB_ENV
working-directory: ${{ inputs.path }}
- name: Scan IaC - tfsec
if: ${{ inputs.enable_TFSEC == 'true' }}
uses: aquasecurity/tfsec-sarif-action@v0.1.4
with:
sarif_file: tfsec.sarif
- name: Upload SARIF file
if: ${{ inputs.enable_TFSEC == 'true' }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: tfsec.sarif
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3.1.1
with:
terraform_version: ${{ inputs.tf_version }}
terraform_wrapper: true
- name: Terraform Format
shell: bash
id: fmt
run: terraform fmt --check --recursive
working-directory: ${{ inputs.path }}
- name: PR Format
if: github.event_name == 'pull_request'
uses: robburger/terraform-pr-commenter@v1.5.0
with:
commenter_type: fmt
commenter_input: ${{ format('{0}{1}', steps.fmt.outputs.stdout, steps.fmt.outputs.stderr) }}
commenter_exitcode: ${{ steps.fmt.outputs.exitcode }}
- name: Terraform Init
shell: bash
id: init
run: terraform init --backend-config="storage_account_name=${{ inputs.az_storage_acc }}" --backend-config="container_name=${{ inputs.az_container_name }}" --backend-config="resource_group_name=${{ inputs.az_resource_group }}" --backend-config="key=${{ inputs.tf_key }}"
working-directory: ${{ inputs.path }}
- name: PR Init
if: github.event_name == 'pull_request'
uses: robburger/terraform-pr-commenter@v1.5.0
with:
commenter_type: init
commenter_input: ${{ format('{0}{1}', steps.init.outputs.stdout, steps.init.outputs.stderr) }}
commenter_exitcode: ${{ steps.init.outputs.exitcode }}
- name: Terraform Validate
shell: bash
id: validate
run: terraform validate
working-directory: ${{ inputs.path }}
- name: PR Validate
if: github.event_name == 'pull_request'
uses: robburger/terraform-pr-commenter@v1.5.0
with:
commenter_type: validate
commenter_input: ${{ format('{0}{1}', steps.validate.outputs.stdout, steps.validate.outputs.stderr) }}
commenter_exitcode: ${{ steps.validate.outputs.exitcode }}
- name: Terraform Plan Deploy
if: ${{ inputs.plan_mode == 'deploy' }}
shell: bash
id: deploy_plan
run: |
terraform plan --var-file=${{ inputs.tf_vars_file }} --out=deploy_plan.tfplan
terraform show -json -no-color deploy_plan.tfplan > deploy_plan_json.json
working-directory: ${{ inputs.path }}
- name: PR Plan Deploy
if: ${{ inputs.plan_mode == 'deploy' && github.event_name == 'pull_request' }}
uses: robburger/terraform-pr-commenter@v1.5.0
with:
commenter_type: plan
commenter_input: ${{ format('{0}{1}', steps.deploy_plan.outputs.stdout, steps.deploy_plan.outputs.stderr) }}
commenter_exitcode: ${{ steps.deploy_plan.outputs.exitcode }}
- name: Terraform Plan Destroy
if: ${{ inputs.plan_mode != 'deploy' }}
shell: bash
id: destroy_plan
run: terraform plan --var-file=${{ inputs.tf_vars_file }} --destroy --out=destroy_plan.tfplan
working-directory: ${{ inputs.path }}
- name: PR Plan Destroy
if: ${{ inputs.plan_mode != 'deploy' && github.event_name == 'pull_request' }}
uses: robburger/terraform-pr-commenter@v1.5.0
with:
commenter_type: plan
commenter_input: ${{ format('{0}{1}', steps.destroy_plan.outputs.stdout, steps.destroy_plan.outputs.stderr) }}
commenter_exitcode: ${{ steps.destroy_plan.outputs.exitcode }}
- name: Compress TF Plan artifact
shell: bash
run: zip -r ${{ inputs.plan_mode }}${{ inputs.tf_key }}.zip ./*
working-directory: ${{ inputs.path }}
- name: Upload Artifact
uses: actions/upload-artifact@v4.3.3
with:
name: "${{ inputs.plan_mode }}-${{ inputs.tf_key }}"
path: "${{ inputs.path }}/${{ inputs.plan_mode }}${{ inputs.tf_key }}.zip"
retention-days: 5