|
| 1 | +name: Terraform Lint Template |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + terraform_version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + description: "Specifies the terraform version." |
| 10 | + working_directory: |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + description: "Specifies the working directory." |
| 14 | + |
| 15 | +permissions: |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + deployment: |
| 20 | + name: Terraform Lint |
| 21 | + runs-on: ubuntu-latest |
| 22 | + continue-on-error: false |
| 23 | + |
| 24 | + steps: |
| 25 | + # Setup Terraform |
| 26 | + - name: Setup Terraform |
| 27 | + id: terraform_setup |
| 28 | + uses: hashicorp/setup-terraform@v2 |
| 29 | + with: |
| 30 | + terraform_version: ${{ inputs.terraform_version }} |
| 31 | + terraform_wrapper: true |
| 32 | + |
| 33 | + # Check Out Repository |
| 34 | + - name: Check Out Repository |
| 35 | + id: checkout_repository |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + # Terraform Format |
| 39 | + - name: Terraform Format |
| 40 | + id: terraform_format |
| 41 | + working-directory: ${{ inputs.working_directory }} |
| 42 | + run: | |
| 43 | + terraform fmt -check -recursive |
| 44 | +
|
| 45 | + # Add Pull Request Comment |
| 46 | + - name: Add Pull Request Comment |
| 47 | + uses: actions/github-script@v6 |
| 48 | + id: pr_comment |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + with: |
| 51 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + script: | |
| 53 | + const output = `#### Terraform Lint Results |
| 54 | + * Terraform Version 📎\`${{ inputs.terraform_version }}\` |
| 55 | + * Working Directory 📂\`${{ inputs.working_directory }}\` |
| 56 | + * Terraform Format and Style 🖌\`${{ steps.terraform_format.outcome }}\``; |
| 57 | +
|
| 58 | + github.rest.issues.createComment({ |
| 59 | + issue_number: context.issue.number, |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + body: output |
| 63 | + }) |
0 commit comments