-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (88 loc) · 2.85 KB
/
basic-plan.yml
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
name: Plan(Basic mode)
on:
pull_request:
branches:
- master
jobs:
plan:
permissions:
id-token: write
pull-requests: write
name: Plan
runs-on: ubuntu-latest
strategy:
matrix:
dir: [
terraform/basic
]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check diff
id: diff
uses: technote-space/[email protected]
with:
PATTERNS: |
${{ matrix.dir }}/**/*.tf
- name: Authenticate to GCP
if: env. GIT_DIFF_FILTERED
id: gcp_auth
uses: google-github-actions/[email protected]
with:
create_credentials_file: 'true'
workload_identity_provider: projects/233207969476/locations/global/workloadIdentityPools/github-action/providers/github-action-provider
service_account: [email protected]
access_token_lifetime: 1200s
- name: gcloud auth login by workload identity
if: env. GIT_DIFF_FILTERED
run: |-
gcloud auth login --brief --cred-file="${{ steps.gcp_auth.outputs.credentials_file_path }}"
- name: Setup terraform
if: env. GIT_DIFF_FILTERED
uses: hashicorp/[email protected]
with:
terraform_version: 1.0.11
- name: Check format
id: fmt
if: env. GIT_DIFF_FILTERED
run: terraform fmt -check -recursive
working-directory: ${{ matrix.dir }}
- name: Initialize
id: init
if: env. GIT_DIFF_FILTERED
run: terraform init
working-directory: ${{ matrix.dir }}
- name: Download modules
if: env. GIT_DIFF_FILTERED
run: terraform get
working-directory: ${{ matrix.dir }}
- name: Validate
if: env. GIT_DIFF_FILTERED
run: terraform validate -no-color
working-directory: ${{ matrix.dir }}
- name: Plan
if: env. GIT_DIFF_FILTERED
id: plan
run: terraform plan -no-color
working-directory: ${{ matrix.dir }}
continue-on-error: true
- name: Comment
if: env. GIT_DIFF_FILTERED
uses: actions/[email protected]
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `## \`${{ matrix.dir }}\`
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`${process.env.PLAN}\`\`\`
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})