forked from fptudsc/fptu-dsc-terraform-workflow-shared
-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (97 loc) · 3.48 KB
/
terraform-pr-review.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
on:
workflow_call:
inputs:
terraform-version:
description: "Terraform version to use"
required: true
type: string
jobs:
plan:
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.FIA_APP_ID }}
installation_id: ${{ secrets.FIA_APP_INSTALLATION_ID }}
private_key: ${{ secrets.DSC_TF_INTEG_PRIVATE_KEY }}
- name: Check out code
uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ inputs.terraform-version }}
- name: Terraform Fmt
id: fmt
run: terraform fmt -check
- name: Terraform init
id: init
run: terraform init
env:
TF_TOKEN_app_terraform_io: ${{ secrets.TERRAFORM_CLOUD_API_TOKEN }}
- name: Terraform validate
id: validate
run: terraform validate
- name: Terraform plan
id: plan
run: terraform plan -no-color
env:
TF_VAR_app_id: ${{ secrets.FIA_APP_ID }}
TF_VAR_installation_id: ${{ secrets.FIA_APP_INSTALLATION_ID }}
TF_VAR_private_key: ${{ secrets.DSC_TF_INTEG_PRIVATE_KEY }}
TF_TOKEN_app_terraform_io: ${{ secrets.TERRAFORM_CLOUD_API_TOKEN }}
- name: Plan output
id: output
uses: actions/github-script@v3
if: github.event_name == 'pull_request' && always()
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const output = `
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`hcl
${process.env.PLAN}
\`\`\`
</details>
**Pusher**: @${{ github.actor }}
**Action**: ${{ github.event_name }}
`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
# - name: Terraform apply
# id: apply
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# run: terraform apply -auto-approve -input=false
# working-directory: ${{ env.working-directory }}
# env:
# TF_VAR_assume_role: "my-github-actions-role"
# - name: Infrastructure tests Output
# if: always()
# uses: actions/github-script@v3
# env:
# INSPEC: "Inspec Test Results \n${{ steps.inspec_results.outputs.loginspec }}"
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# const output = `#### Inspec Tests 🖌\`${{ steps.inspec.outcome }}\`
# <details><summary>Show Test Results</summary>
# \`\`\`
# ${process.env.INSPEC}
# \`\`\`
# </details>
# `;
# github.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: output
# })