|
8 | 8 | jobs: |
9 | 9 | terraform: |
10 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + pull-requests: write |
11 | 14 | env: |
12 | 15 | TF_VAR_cf_api_token: ${{ secrets.TF_VAR_CF_API_TOKEN }} |
13 | 16 | TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} |
|
19 | 22 | with: |
20 | 23 | terraform_version: ~1.0 |
21 | 24 |
|
| 25 | + - name: Cache Terraform plugins |
| 26 | + uses: actions/cache@v4 |
| 27 | + with: |
| 28 | + path: ~/.terraform.d/plugin-cache |
| 29 | + key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} |
| 30 | + restore-keys: | |
| 31 | + ${{ runner.os }}-terraform- |
| 32 | +
|
22 | 33 | - name: Terraform Format |
23 | 34 | run: terraform fmt -check -recursive |
24 | 35 |
|
|
28 | 39 | - name: Terraform Validate |
29 | 40 | run: terraform validate |
30 | 41 |
|
| 42 | + - name: Terraform Plan |
| 43 | + id: plan |
| 44 | + if: github.event_name == 'pull_request' |
| 45 | + run: terraform plan -no-color |
| 46 | + continue-on-error: true |
| 47 | + |
| 48 | + - name: Comment PR with Plan |
| 49 | + if: github.event_name == 'pull_request' |
| 50 | + uses: actions/github-script@v7 |
| 51 | + env: |
| 52 | + PLAN: "${{ steps.plan.outputs.stdout }}" |
| 53 | + with: |
| 54 | + script: | |
| 55 | + const output = `#### Terraform Plan 📖 |
| 56 | + |
| 57 | + <details><summary>Show Plan</summary> |
| 58 | + |
| 59 | + \`\`\`terraform |
| 60 | + ${process.env.PLAN} |
| 61 | + \`\`\` |
| 62 | + |
| 63 | + </details> |
| 64 | + |
| 65 | + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 66 | + |
| 67 | + github.rest.issues.createComment({ |
| 68 | + issue_number: context.issue.number, |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + body: output |
| 72 | + }) |
| 73 | +
|
31 | 74 | - name: Setup TFLint |
32 | 75 | uses: terraform-linters/setup-tflint@v4 |
33 | 76 |
|
|
38 | 81 |
|
39 | 82 | - name: TFSec Security Scan |
40 | 83 | uses: aquasecurity/tfsec-action@v1.0.3 |
| 84 | + continue-on-error: true |
41 | 85 |
|
42 | 86 | - name: Checkov Security Scan |
43 | 87 | uses: bridgecrewio/checkov-action@v12 |
| 88 | + continue-on-error: true |
44 | 89 | with: |
45 | 90 | directory: . |
46 | 91 | framework: terraform |
0 commit comments