forked from clouddrove/github-shared-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (173 loc) · 6.93 KB
/
Copy pathstf-checks.yml
File metadata and controls
192 lines (173 loc) · 6.93 KB
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
---
# Tf check workflow checks for min, max version, terraform fmt, terraform init & terraform validate in your terraform code.
name: 🧪 tf Checks
on:
workflow_call:
inputs:
working_directory:
description: 'Directory where a complete example exists for the module.'
required: false
type: string
default: './examples/complete/'
provider:
required: false
type: string
description: 'Cloud provider to run the workflow. e.g. azurerm or aws or gcp'
terraform_version:
description: 'Terraform version to use. Leave empty for the latest version.'
required: false
type: string
aws_region:
required: false
type: string
default: us-east-1
description: 'AWS region of terraform deployment.'
role_duration_seconds:
required: false
type: number
default: 3600
description: 'The assumed role duration in seconds, if assuming a role. Defaults to 1 hour (3600 seconds). Acceptable values range from 15 minutes (900 seconds) to 12 hours (43200 seconds).'
gcp_credentials:
description: 'GCP credentials to use.'
required: false
default: false
type: string
token_format:
required: false
type: string
default: access_token
description: 'Output format for the generated authentication token. For OAuth 2.0 access tokens, specify "access_token". For OIDC tokens, specify "id_token". To skip token generation, leave this value empty'
access_token_lifetime:
required: false
type: string
default: 300s
description: 'Desired lifetime duration of the access token, in seconds'
project_id:
required: false
type: string
description: 'ID of the default project to use for future API calls and invocations.'
create_credentials_file:
required: false
type: string
default: true
description: 'If true, the action will securely generate a credentials file which can be used for authentication via gcloud and Google Cloud SDKs.'
secrets:
AZURE_CREDENTIALS:
required: false
description: 'Azure Credentials to install Azure in github runner.'
AWS_ACCESS_KEY_ID:
description: 'aws access keys'
required: false
AWS_SECRET_ACCESS_KEY:
description: 'aws secret access keys'
required: false
AWS_SESSION_TOKEN:
required: false
description: 'AWS Session Token to install AWS CLI'
BUILD_ROLE:
required: false
description: 'AWS OIDC role for aws authentication.'
GCP_CREDENTIALS:
description: 'The Google Cloud JSON service account key to use for authentication'
required: false
WORKLOAD_IDENTITY_PROVIDER:
required: false
description: 'The full identifier of the Workload Identity Provider'
SERVICE_ACCOUNT:
required: false
description: 'The service account to be used'
jobs:
# - Terraform version extract as output.
versionExtract:
name: 🏷️ Get min/max versions
runs-on: ubuntu-latest
outputs:
minVersion: ${{ steps.minMax.outputs.minVersion }}
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
steps:
# - Checkout the repository to the GitHub Actions runner
- name: 📦 Checkout Repository
uses: actions/checkout@v7
# - Checking terraform Max and Min version.
- name: 🧮 Terraform min/max versions
id: minMax
uses: clowdhaus/terraform-min-max@main
# - Evaluating terraform version based on version extract
versionEvaluate:
name: 🧪 Evaluate Terraform versions
runs-on: ubuntu-latest
needs: versionExtract
strategy:
fail-fast: false
matrix:
version:
- ${{ needs.versionExtract.outputs.minVersion }}
- ${{ needs.versionExtract.outputs.maxVersion }}
directory:
- ${{ inputs.working_directory }}
steps:
# - Checkout the repository to the GitHub Actions runner
- name: 📦 Checkout Repository
uses: actions/checkout@v7
- name: ☁️ Install AWS CLI
if: ${{ inputs.provider == 'aws' }}
uses: aws-actions/configure-aws-credentials@v6
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
role-to-assume: ${{ secrets.BUILD_ROLE }}
aws-region: ${{ inputs.aws_region }}
role-duration-seconds: ${{ inputs.role_duration_seconds }}
role-skip-session-tagging: true
- name: ☁️ Install Azure CLI
if: ${{ inputs.provider == 'azurerm' }}
uses: azure/login@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: ☁️ Authenticate to Google Cloud
if: ${{ inputs.provider == 'gcp' }}
uses: 'google-github-actions/auth@v3'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
create_credentials_file: ${{ inputs.create_credentials_file }}
token_format: ${{ inputs.token_format }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
access_token_lifetime: ${{ inputs.access_token_lifetime }}
project_id: ${{ inputs.project_id }}
# - Installing terraform version based on version extract.
- name: 🛠️ Install Terraform v${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
uses: hashicorp/setup-terraform@v4
with:
terraform_version: ${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
# - Setup smurf CLI
- name: Setup Smurf
uses: clouddrove/smurf@v1.1.3
# - Terraform checks to Init and Validate terraform code.
- name: 🏗️ Init & validate v${{ matrix.version }}
run: |
cd ${{ matrix.directory }}
smurf stf init
smurf stf validate
# Action to verify terraform formatting.
format:
name: 🧹 Check code format
runs-on: ubuntu-latest
needs: [versionExtract, versionEvaluate]
steps:
# - Checkout the repository to the GitHub Actions runner
- name: 📦 Checkout Repository
uses: actions/checkout@v7
# - Action added to install terraform
- name: 🛠️ Install Terraform v${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
uses: hashicorp/setup-terraform@v4
with:
terraform_version: ${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
# - Setup smurf
- name: Setup Smurf
uses: clouddrove/smurf@v1.1.3
# - Running command to check terraform formatting changes.
- name: 🧹 Check Terraform format changes
run: smurf stf fmt --recursive --timeout 5s
...