2626 terraform_version :
2727 type : string
2828 default : 1.3.6
29- description : ' Required erraform version'
29+ description : ' Required terraform version'
3030 token_format :
3131 required : false
3232 type : string
@@ -147,8 +147,8 @@ jobs:
147147
148148 - name : terraform init
149149 run : |
150- cd ${{ inputs.working_directory }}
151- terraform init
150+ cd ${{ inputs.working_directory }}
151+ terraform init
152152
153153 # Generates an execution plan for Terraform
154154 # An exit code of 0 indicated no changes, 1 a terraform failure, 2 there are pending changes.
@@ -157,9 +157,9 @@ jobs:
157157 run : |
158158 cd ${{ inputs.working_directory }}
159159 if [ -n "${{ inputs.var_file }}" ]; then
160- terraform plan -detailed-exitcode -no-color -out tfplan --var-file=${{ inputs.var_file }} || export exitcode=$?
160+ terraform plan -detailed-exitcode -no-color -out tfplan --var-file=${{ inputs.var_file }} || export exitcode=$?
161161 else
162- terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
162+ terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
163163 fi
164164
165165 # Save plan to artifacts
@@ -178,6 +178,7 @@ jobs:
178178 delimiter="$(openssl rand -hex 8)"
179179 echo "summary<<${delimiter}" >> $GITHUB_OUTPUT
180180 echo "## Terraform Plan Output" >> $GITHUB_OUTPUT
181+ echo "### Working Directory: \`${{ inputs.working_directory }}\`" >> $GITHUB_OUTPUT
181182 echo "<details><summary>Click to expand</summary>" >> $GITHUB_OUTPUT
182183 echo "" >> $GITHUB_OUTPUT
183184 echo '```terraform' >> $GITHUB_OUTPUT
@@ -202,44 +203,44 @@ jobs:
202203 with :
203204 github-token : ${{ secrets.GITHUB }}
204205 script : |
205- const body = `${process.env.SUMMARY}`;
206- const title = 'Terraform Configuration Drift Detected';
207- const creator = 'github-actions[bot]'
206+ const body = `${process.env.SUMMARY}`;
207+ const title = 'Terraform Configuration Drift Detected';
208+ const creator = 'github-actions[bot]'
208209
209- // Look to see if there is an existing drift issue
210- const issues = await github.rest.issues.listForRepo({
211- owner: context.repo.owner,
212- repo: context.repo.repo,
213- state: 'open',
214- creator: creator,
215- title: title
216- })
210+ // Look to see if there is an existing drift issue
211+ const issues = await github.rest.issues.listForRepo({
212+ owner: context.repo.owner,
213+ repo: context.repo.repo,
214+ state: 'open',
215+ creator: creator,
216+ title: title
217+ })
217218
218- if( issues.data.length > 0 ) {
219- // We assume there shouldn't be more than 1 open issue, since we update any issue we find
220- const issue = issues.data[0]
219+ if( issues.data.length > 0 ) {
220+ // We assume there shouldn't be more than 1 open issue, since we update any issue we find
221+ const issue = issues.data[0]
221222
222- if ( issue.body == body ) {
223- console.log('Drift Detected: Found matching issue with duplicate content')
224- } else {
225- console.log('Drift Detected: Found matching issue, updating body')
226- github.rest.issues.update({
227- owner: context.repo.owner,
228- repo: context.repo.repo,
229- issue_number: issue.number,
230- body: body
231- })
232- }
223+ if ( issue.body == body ) {
224+ console.log('Drift Detected: Found matching issue with duplicate content')
233225 } else {
234- console.log('Drift Detected: Creating new issue')
235-
236- github.rest.issues.create({
226+ console.log('Drift Detected: Found matching issue, updating body')
227+ github.rest.issues.update({
237228 owner: context.repo.owner,
238229 repo: context.repo.repo,
239- title: title ,
230+ issue_number: issue.number ,
240231 body: body
241- })
232+ })
242233 }
234+ } else {
235+ console.log('Drift Detected: Creating new issue')
236+
237+ github.rest.issues.create({
238+ owner: context.repo.owner,
239+ repo: context.repo.repo,
240+ title: title,
241+ body: body
242+ })
243+ }
243244
244245 # If changes aren't detected, close any open drift issues
245246 - name : Publish Drift Report
@@ -248,28 +249,28 @@ jobs:
248249 with :
249250 github-token : ${{ secrets.GITHUB }}
250251 script : |
251- const title = 'Terraform Configuration Drift Detected';
252- const creator = 'github-actions[bot]'
252+ const title = 'Terraform Configuration Drift Detected';
253+ const creator = 'github-actions[bot]'
254+
255+ // Look to see if there is an existing drift issue
256+ const issues = await github.rest.issues.listForRepo({
257+ owner: context.repo.owner,
258+ repo: context.repo.repo,
259+ state: 'open',
260+ creator: creator,
261+ title: title
262+ })
263+
264+ if( issues.data.length > 0 ) {
265+ const issue = issues.data[0]
253266
254- // Look to see if there is an existing drift issue
255- const issues = await github.rest.issues.listForRepo({
267+ github.rest.issues.update({
256268 owner: context.repo.owner,
257269 repo: context.repo.repo,
258- state: 'open',
259- creator: creator,
260- title: title
270+ issue_number: issue.number,
271+ state: 'closed'
261272 })
262-
263- if( issues.data.length > 0 ) {
264- const issue = issues.data[0]
265-
266- github.rest.issues.update({
267- owner: context.repo.owner,
268- repo: context.repo.repo,
269- issue_number: issue.number,
270- state: 'closed'
271- })
272- }
273+ }
273274
274275 # Mark the workflow as failed if drift detected
275276 - name : Error on Failure
0 commit comments