-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (196 loc) · 7.5 KB
/
terraform.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: terraform
on:
push:
branches:
- main
pull_request:
permissions:
pull-requests: write
jobs:
check-diff:
runs-on: ubuntu-24.04
outputs:
target: ${{ steps.changes.outputs.target == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
target:
- 'terraform/**/*'
- '.github/workflows/terraform.yml'
- 'aqua.yaml'
terraform-fmt:
runs-on: ubuntu-24.04
needs: [check-diff]
if: needs.check-diff.outputs.target == 'true'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Run terraform fmt
working-directory: "./terraform"
run: terraform fmt -check -recursive
terraform-validate:
name: terraform-validate (${{ matrix.dir }})
runs-on: ubuntu-24.04
needs: [check-diff]
if: needs.check-diff.outputs.target == 'true'
strategy:
matrix:
include:
- { dir: cdn.koyashiro.net, prefix: CDN_KOYASHIRO_NET }
- { dir: vpm.koyashiro.net, prefix: VPM_KOYASHIRO_NET }
- { dir: koyashi.ro, prefix: KOYASHI_RO }
- { dir: koyashiro.com, prefix: KOYASHIRO_COM }
- { dir: koyashiro.dev, prefix: KOYASHIRO_DEV }
- { dir: koyashiro.jp, prefix: KOYASHIRO_JP }
- { dir: koyashiro.live, prefix: KOYASHIRO_LIVE }
- { dir: koyashiro.me, prefix: KOYASHIRO_ME }
- { dir: koyashiro.net, prefix: KOYASHIRO_NET }
- { dir: koyashiro.sh, prefix: KOYASHIRO_SH }
env:
TF_WORKSPACE: ${{ secrets[format('TF_WORKSPACE_{0}', matrix.prefix)] }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Export secrets
uses: koyashiro/export-secrets@97186061e694b133f51a120945a687cc7844c771 # v0.6.0
with:
secrets: ${{ toJSON(secrets) }}
downcase-tf-var: true
downcase-tf-token: true
- name: Run terraform init
working-directory: "./terraform/${{ matrix.dir }}"
run: terraform init
- name: Run terraform validate
working-directory: "./terraform/${{ matrix.dir }}"
run: terraform validate
tflint:
runs-on: ubuntu-24.04
needs: [check-diff]
if: needs.check-diff.outputs.target == 'true'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Cache tflint plugin dir
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('terraform/.tflint.hcl') }}
- name: Init TFLint
working-directory: "./terraform"
run: tflint --init
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run TFLint
working-directory: "./terraform"
run: tflint --recursive
trivy:
runs-on: ubuntu-24.04
needs: [check-diff]
if: needs.check-diff.outputs.target == 'true'
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Run Trivy
run: trivy config .
terraform-plan:
name: terraform-plan (${{ matrix.dir }})
runs-on: ubuntu-24.04
needs: [check-diff]
if: needs.check-diff.outputs.target == 'true'
strategy:
matrix:
include:
- { dir: cdn.koyashiro.net, prefix: CDN_KOYASHIRO_NET }
- { dir: vpm.koyashiro.net, prefix: VPM_KOYASHIRO_NET }
- { dir: koyashi.ro, prefix: KOYASHI_RO }
- { dir: koyashiro.com, prefix: KOYASHIRO_COM }
- { dir: koyashiro.dev, prefix: KOYASHIRO_DEV }
- { dir: koyashiro.jp, prefix: KOYASHIRO_JP }
- { dir: koyashiro.live, prefix: KOYASHIRO_LIVE }
- { dir: koyashiro.me, prefix: KOYASHIRO_ME }
- { dir: koyashiro.net, prefix: KOYASHIRO_NET }
- { dir: koyashiro.sh, prefix: KOYASHIRO_SH }
env:
TF_WORKSPACE: ${{ secrets[format('TF_WORKSPACE_{0}', matrix.prefix)] }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Export secrets
uses: koyashiro/export-secrets@97186061e694b133f51a120945a687cc7844c771 # v0.6.0
with:
secrets: ${{ toJSON(secrets) }}
downcase-tf-var: true
downcase-tf-token: true
- name: Run terraform init
working-directory: "./terraform/${{ matrix.dir }}"
run: terraform init
- name: Run terraform plan
working-directory: "./terraform/${{ matrix.dir }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: tfcmt -var target:${{ matrix.dir }} plan -patch -- terraform plan -no-color
terraform-apply:
name: terraform-apply (${{ matrix.dir }})
runs-on: ubuntu-24.04
needs: [check-diff, terraform-plan]
if: needs.check-diff.outputs.target == 'true' && github.ref == 'refs/heads/main'
strategy:
matrix:
include:
- { dir: cdn.koyashiro.net, prefix: CDN_KOYASHIRO_NET }
- { dir: vpm.koyashiro.net, prefix: VPM_KOYASHIRO_NET }
- { dir: koyashi.ro, prefix: KOYASHI_RO }
- { dir: koyashiro.com, prefix: KOYASHIRO_COM }
- { dir: koyashiro.dev, prefix: KOYASHIRO_DEV }
- { dir: koyashiro.jp, prefix: KOYASHIRO_JP }
- { dir: koyashiro.live, prefix: KOYASHIRO_LIVE }
- { dir: koyashiro.me, prefix: KOYASHIRO_ME }
- { dir: koyashiro.net, prefix: KOYASHIRO_NET }
- { dir: koyashiro.sh, prefix: KOYASHIRO_SH }
env:
TF_WORKSPACE: ${{ secrets[format('TF_WORKSPACE_{0}', matrix.prefix)] }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install aqua
uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.2
- name: Export secrets
uses: koyashiro/export-secrets@97186061e694b133f51a120945a687cc7844c771 # v0.6.0
with:
secrets: ${{ toJSON(secrets) }}
downcase-tf-var: true
downcase-tf-token: true
- name: Run terraform init
working-directory: "./terraform/${{ matrix.dir }}"
run: terraform init
- name: Run terraform apply
working-directory: "./terraform/${{ matrix.dir }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: tfcmt -var target:${{ matrix.dir }} apply -- terraform apply -auto-approve -no-color