|
9 | 9 | jobs:
|
10 | 10 | tflint:
|
11 | 11 | name: TFLint
|
12 |
| - runs-on: ubuntu-latest |
13 |
| - |
14 |
| - steps: |
15 |
| - - name: Checkout |
16 |
| - uses: actions/checkout@v3 |
17 |
| - |
18 |
| - - name: Setup TFLint |
19 |
| - uses: terraform-linters/setup-tflint@v3 |
20 |
| - |
21 |
| - - name: Init TFLint |
22 |
| - run: tflint --init |
23 |
| - env: |
24 |
| - # https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting |
25 |
| - GITHUB_TOKEN: ${{ github.token }} |
26 |
| - |
27 |
| - - name: Run TFLint |
28 |
| - run: tflint -f compact |
| 12 | + uses: soat-tech-challenge/github-workflows/.github/workflows/tflint.yml@main |
29 | 13 |
|
30 | 14 | tfsec:
|
31 |
| - name: tfsec |
32 |
| - runs-on: ubuntu-latest |
| 15 | + uses: soat-tech-challenge/github-workflows/.github/workflows/tfsec.yml@main |
33 | 16 |
|
34 | 17 | permissions:
|
35 | 18 | contents: read
|
36 | 19 | pull-requests: write
|
37 | 20 |
|
38 |
| - steps: |
39 |
| - - name: Checkout |
40 |
| - uses: actions/checkout@v3 |
41 |
| - |
42 |
| - - name: tfsec |
43 |
| - uses: aquasecurity/[email protected] |
44 |
| - with: |
45 |
| - tfsec_args: --soft-fail |
46 |
| - github_token: ${{ github.token }} |
47 |
| - |
48 |
| - terraform-cloud-speculative-run: |
49 |
| - name: Terraform Cloud Speculative Run |
50 |
| - runs-on: ubuntu-latest |
| 21 | + terraform-plan: |
| 22 | + name: Terraform Plan |
| 23 | + uses: soat-tech-challenge/github-workflows/.github/workflows/terraform-plan.yml@main |
| 24 | + secrets: inherit |
| 25 | + with: |
| 26 | + cloud_workspace: database-staging |
51 | 27 |
|
52 | 28 | permissions:
|
53 | 29 | contents: read
|
54 | 30 | pull-requests: write
|
55 |
| - |
56 |
| - env: |
57 |
| - TF_CLOUD_ORGANIZATION: ${{ vars.TF_CLOUD_ORGANIZATION }} |
58 |
| - TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} |
59 |
| - TF_WORKSPACE: ${{ vars.TF_WORKSPACE }} |
60 |
| - CONFIG_DIRECTORY: ${{ vars.CONFIG_DIRECTORY }} |
61 |
| - |
62 |
| - steps: |
63 |
| - - name: Checkout |
64 |
| - uses: actions/checkout@v3 |
65 |
| - |
66 |
| - - name: Upload Configuration |
67 |
| - uses: hashicorp/tfc-workflows-github/actions/[email protected] |
68 |
| - id: upload |
69 |
| - with: |
70 |
| - workspace: ${{ env.TF_WORKSPACE }} |
71 |
| - directory: ${{ env.CONFIG_DIRECTORY }} |
72 |
| - speculative: true |
73 |
| - |
74 |
| - - name: Create Plan Run |
75 |
| - uses: hashicorp/tfc-workflows-github/actions/[email protected] |
76 |
| - id: run |
77 |
| - ## run may fail, if so continue to output PR comment |
78 |
| - ## step.terraform-cloud-check-run-status will fail job after pr comment is created/updated. |
79 |
| - continue-on-error: true |
80 |
| - with: |
81 |
| - workspace: ${{ env.TF_WORKSPACE }} |
82 |
| - configuration_version: ${{ steps.upload.outputs.configuration_version_id }} |
83 |
| - plan_only: true |
84 |
| - |
85 |
| - - name: Get Plan Output |
86 |
| - uses: hashicorp/tfc-workflows-github/actions/[email protected] |
87 |
| - id: plan-output |
88 |
| - with: |
89 |
| - plan: ${{ steps.run.outputs.plan_id }} |
90 |
| - |
91 |
| - - name: Update PR with Plan comment |
92 |
| - uses: actions/github-script@v6 |
93 |
| - if: github.event_name == 'pull_request' |
94 |
| - with: |
95 |
| - github-token: ${{ secrets.GITHUB_TOKEN }} |
96 |
| - script: | |
97 |
| - // 1. Retrieve existing bot comments for the PR |
98 |
| - const { data: comments } = await github.rest.issues.listComments({ |
99 |
| - owner: context.repo.owner, |
100 |
| - repo: context.repo.repo, |
101 |
| - issue_number: context.issue.number, |
102 |
| - }) |
103 |
| - const botComment = comments.find(comment => { |
104 |
| - return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output') |
105 |
| - }) |
106 |
| - const output = `#### Terraform Cloud Plan Output |
107 |
| - \`\`\` |
108 |
| - Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy. |
109 |
| - \`\`\` |
110 |
| - [Terraform Cloud Plan](${{ steps.run.outputs.run_link }}) |
111 |
| - ` |
112 |
| - // 3. If we have a comment, update it, otherwise create a new one |
113 |
| - if (botComment) { |
114 |
| - github.rest.issues.updateComment({ |
115 |
| - owner: context.repo.owner, |
116 |
| - repo: context.repo.repo, |
117 |
| - comment_id: botComment.id, |
118 |
| - body: output |
119 |
| - }) |
120 |
| - } else { |
121 |
| - github.rest.issues.createComment({ |
122 |
| - issue_number: context.issue.number, |
123 |
| - owner: context.repo.owner, |
124 |
| - repo: context.repo.repo, |
125 |
| - body: output |
126 |
| - }) |
127 |
| - } |
128 |
| -
|
129 |
| - ## Check Run Status, if not planned_and_finished fail the job |
130 |
| - - id: terraform-cloud-check-run-status |
131 |
| - if: ${{ steps.run.outputs.run_status != 'planned_and_finished'}} |
132 |
| - run: | |
133 |
| - echo "Terraform Cloud Run Failed or Requires Further Attention" |
134 |
| - echo "Run Status: '${{ steps.run.outputs.run_status }}'" |
135 |
| - echo "${{ steps.run.outputs.run_link }}" |
136 |
| - exit 1 |
0 commit comments