Skip to content

Commit 14ebc28

Browse files
authored
Merge pull request #29 from clouddrove/tfdrift
feat: Update workflow to work with var files
2 parents 7e96c3c + 39c8623 commit 14ebc28

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

.github/workflows/tfdrift.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,24 @@ on:
1818
type: string
1919
default: us-east-1
2020
description: 'AWS region of terraform deployment.'
21-
21+
var_file:
22+
required: false
23+
default: ""
24+
type: string
25+
description: 'Terraform var file directory. e.g. vars/dev.tfvars'
26+
secrets:
27+
AZURE_CREDENTIALS:
28+
required: false
29+
description: 'Azure Credentials to install Azure in github runner.'
30+
aws_access_key_id:
31+
required: false
32+
description: 'AWS Access Key ID to install AWS CLI.'
33+
aws_secret_access_key:
34+
required: false
35+
description: 'AWS Secret access key to install AWS CLI'
36+
GITHUB:
37+
required: true
38+
description: 'PAT of the user to run the jobs.'
2239
jobs:
2340
terraform-plan:
2441
name: 'Terraform Plan'
@@ -77,8 +94,12 @@ jobs:
7794
run: |
7895
export exitcode=0
7996
cd ${{ inputs.working_directory }}
97+
if [ -n "${{ inputs.var_file }}" ]; then
98+
terraform plan -detailed-exitcode -no-color -out tfplan --var-file=${{ inputs.var_file }} || export exitcode=$?
99+
else
80100
terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
81-
101+
fi
102+
82103
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
83104
84105
if [ $exitcode -eq 1 ]; then
@@ -173,7 +194,7 @@ jobs:
173194
if: steps.tf-plan.outputs.exitcode == 0
174195
uses: actions/github-script@v6
175196
with:
176-
github-token: ${{ secrets.GITHUB_TOKEN }}
197+
github-token: ${{ secrets.GITHUB }}
177198
script: |
178199
const title = 'Terraform Configuration Drift Detected';
179200
const creator = 'github-actions[bot]'
@@ -202,3 +223,4 @@ jobs:
202223
- name: Error on Failure
203224
if: steps.tf-plan.outputs.exitcode == 2
204225
run: exit 1
226+

0 commit comments

Comments
 (0)