4949 TF_API_TOKEN :
5050 required : false
5151 description : ' Terraform cloud token if your backend is terraform cloud.'
52+ env-vars :
53+ required : false
54+ description : ' Pass required environment variables'
55+
5256jobs :
5357 terraform-plan :
5458 name : ' Terraform Plan'
6468 - name : Checkout
6569 uses : actions/checkout@v4
6670
71+ - name : Set environment variables
72+ run : |
73+ (
74+ cat <<'_EOT'
75+ ${{ secrets.env-vars }}
76+ _EOT
77+ ) >> "$GITHUB_ENV"
78+
6779 - name : Install AWS CLI
6880 if : ${{ inputs.provider == 'aws' }}
6981 uses : aws-actions/configure-aws-credentials@v4
@@ -102,20 +114,12 @@ jobs:
102114 - name : Terraform Plan
103115 id : tf-plan
104116 run : |
105- export exitcode=0
106117 cd ${{ inputs.working_directory }}
107118 if [ -n "${{ inputs.var_file }}" ]; then
108119 terraform plan -detailed-exitcode -no-color -out tfplan --var-file=${{ inputs.var_file }} || export exitcode=$?
109120 else
110121 terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
111122 fi
112- echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
113- if [ $exitcode -eq 1 ]; then
114- echo Terraform Plan Failed!
115- exit 1
116- else
117- exit 0
118- fi
119123
120124 # Save plan to artifacts
121125 - name : Publish Terraform Plan
@@ -149,7 +153,7 @@ jobs:
149153 echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
150154
151155 # If changes are detected, create a new issue
152- - name : Publish Drift Report
156+ - name : Publish Drift Report and create new issue
153157 if : steps.tf-plan.outputs.exitcode == 2
154158 uses : actions/github-script@v6
155159 env :
@@ -161,18 +165,20 @@ jobs:
161165 const title = 'Terraform Configuration Drift Detected';
162166 const creator = 'github-actions[bot]'
163167
164- # Look to see if there is an existing drift issue
168+ // Look to see if there is an existing drift issue
165169 const issues = await github.rest.issues.listForRepo({
166170 owner: context.repo.owner,
167171 repo: context.repo.repo,
168172 state: 'open',
169173 creator: creator,
170174 title: title
171175 })
176+
172177 if( issues.data.length > 0 ) {
173178 // We assume there shouldn't be more than 1 open issue, since we update any issue we find
174179 const issue = issues.data[0]
175- if ( issue.body == body ) {
180+
181+ if ( issue.body == body ) {
176182 console.log('Drift Detected: Found matching issue with duplicate content')
177183 } else {
178184 console.log('Drift Detected: Found matching issue, updating body')
@@ -185,6 +191,7 @@ jobs:
185191 }
186192 } else {
187193 console.log('Drift Detected: Creating new issue')
194+
188195 github.rest.issues.create({
189196 owner: context.repo.owner,
190197 repo: context.repo.repo,
@@ -203,16 +210,18 @@ jobs:
203210 const title = 'Terraform Configuration Drift Detected';
204211 const creator = 'github-actions[bot]'
205212
206- # Look to see if there is an existing drift issue
213+ // Look to see if there is an existing drift issue
207214 const issues = await github.rest.issues.listForRepo({
208215 owner: context.repo.owner,
209216 repo: context.repo.repo,
210217 state: 'open',
211218 creator: creator,
212219 title: title
213220 })
214- if( issues.data.length > 0 ){
221+
222+ if( issues.data.length > 0 ) {
215223 const issue = issues.data[0]
224+
216225 github.rest.issues.update({
217226 owner: context.repo.owner,
218227 repo: context.repo.repo,
0 commit comments