-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (238 loc) · 8.47 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Infrastructure
on:
push:
branches:
- master
issue_comment:
types: [created, edited]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
checks:
name: Terraform Planning
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup Yarn
run: yarn install
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.14.10
- name: Terraform Format
id: fmt
working-directory: infra
run: terraform fmt -check -recursive
- name: Terraform Init
id: init
if: github.event_name == 'pull_request'
working-directory: infra/stages/staging
run: terraform init
continue-on-error: true
- name: Terraform Plan
id: plan
if: github.event_name == 'pull_request'
working-directory: infra/stages/staging
run: terraform plan -no-color
continue-on-error: true
- name: Update Pull Request
uses: actions/github-script@v4
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentBody = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
<pre>${process.env.PLAN}</pre>
</details>`;
const {data: comments} = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
})
// Find any comment already made by the bot.
const existingComment = comments.find(comment => comment.user.id === 41898282)
if (existingComment) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
})
} else {
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
body: commentBody
})
}
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
develop_deploy:
name: Terraform Develop Deploy
runs-on: ubuntu-latest
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.comment.body == 'deploy'
env:
VUE_APP_API_BASE_URI: https://staging.thalia.nu
VUE_APP_API_AUTHORIZATION_ENDPOINT: /user/oauth/authorize/
VUE_APP_API_ACCESS_TOKEN_ENDPOINT: /user/oauth/token/
VUE_APP_API_OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
VUE_APP_API_OAUTH_REDIRECT_URI: https://thadmin-develop.technicie.nl/auth/callback
VUE_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
VUE_APP_SENTRY_RELEASE: ${{ github.sha }}
VUE_APP_SENTRY_ENVIRONMENT: develop
environment:
name: Develop
url: https://thadmin-develop.technicie.nl
steps:
- name: Get branch
id: get-branch
uses: octokit/[email protected]
with:
route: GET /repos/:repository/pulls/:issue_id
repository: ${{ github.repository }}
issue_id: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ fromJson(steps.get-branch.outputs.data).head.ref }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.14.10
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup Yarn
run: yarn install
- name: Terraform Apply
working-directory: infra/stages/develop
run: terraform init && terraform apply -auto-approve
- name: Comment in PR
uses: octokit/[email protected]
with:
route: GET /repos/:repository/pulls/:issue_id/comments
repository: ${{ github.repository }}
issue_id: ${{ github.event.issue.number }}
body: Latest changes in this PR have been deployed to https://thadmin-develop.technicie.nl/.
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
staging_deploy:
name: Terraform Staging Deploy
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
env:
VUE_APP_API_BASE_URI: https://staging.thalia.nu
VUE_APP_API_AUTHORIZATION_ENDPOINT: /user/oauth/authorize/
VUE_APP_API_ACCESS_TOKEN_ENDPOINT: /user/oauth/token/
VUE_APP_API_OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
VUE_APP_API_OAUTH_REDIRECT_URI: https://thadmin-staging.technicie.nl/auth/callback
VUE_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
VUE_APP_SENTRY_RELEASE: ${{ github.sha }}
VUE_APP_SENTRY_ENVIRONMENT: staging
environment:
name: Staging
url: https://thadmin-staging.technicie.nl
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.14.10
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup Yarn
run: yarn install
- name: Terraform Apply
working-directory: infra/stages/staging
run: terraform init && terraform apply -auto-approve
production_deploy:
name: Terraform Production Deploy
if: github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
VUE_APP_API_BASE_URI: https://thalia.nu
VUE_APP_API_AUTHORIZATION_ENDPOINT: /user/oauth/authorize/
VUE_APP_API_ACCESS_TOKEN_ENDPOINT: /user/oauth/token/
VUE_APP_API_OAUTH_CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}
VUE_APP_API_OAUTH_REDIRECT_URI: https://thadmin.thalia.nu/auth/callback
VUE_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
VUE_APP_SENTRY_RELEASE: ${{ github.sha }}
VUE_APP_SENTRY_ENVIRONMENT: production
environment:
name: Production
url: https://thadmin.thalia.nu
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.14.10
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Setup Yarn
run: yarn install
- name: Terraform Apply
working-directory: infra/stages/production
run: terraform init && terraform apply -auto-approve