-
Notifications
You must be signed in to change notification settings - Fork 68
/
cicd.hcl
347 lines (341 loc) · 11.8 KB
/
cicd.hcl
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
schema = {
title = "CICD Recipe"
additionalProperties = false
required = [
"envs",
"terraform_root",
"scheduler_region",
"service_account",
"logs_bucket"
]
properties = {
project_id = {
description = "ID of project to deploy CICD in."
type = "string"
pattern = "^[a-z][a-z0-9\\-]{4,28}[a-z0-9]$"
}
github = {
description = "Config for GitHub Cloud Build triggers."
type = "object"
additionalProperties = false
properties = {
owner = {
description = "GitHub repo owner."
type = "string"
}
name = {
description = "GitHub repo name."
type = "string"
}
}
}
cloud_source_repository = {
description = <<EOF
Config for Google Cloud Source Repository.
IMPORTANT: Cloud Source Repositories does not support code review or
presubmit runs. If you set both plan and apply to run at the same time,
they will conflict and may error out. To get around this, for 'shared'
and 'prod' environment, set 'apply' trigger to not 'run_on_push',
and for other environments, do not specify the 'plan' trigger block
and let 'apply' trigger 'run_on_push'.
EOF
type = "object"
additionalProperties = false
required = [
"name",
]
properties = {
name = {
description = <<EOF
Cloud Source Repository repo name.
The Cloud Source Repository should be hosted under the devops project.
EOF
type = "string"
}
readers = {
description = <<EOF
IAM members to allow reading the repo.
EOF
type = "array"
items = {
type = "string"
}
}
writers = {
description = <<EOF
IAM members to allow writing to the repo.
EOF
type = "array"
items = {
type = "string"
}
}
}
}
build_viewers = {
description = <<EOF
IAM members to grant `cloudbuild.builds.viewer` role in the devops project
to see CICD results.
EOF
type = "array"
items = {
type = "string"
}
}
build_editors = {
description = <<EOF
IAM members to grant `cloudbuild.builds.editor` role in the devops project
to see CICD results.
EOF
type = "array"
items = {
type = "string"
}
}
scheduler_region = {
description = <<EOF
[Region](https://cloud.google.com/sdk/gcloud/reference/scheduler/locations/list) where the scheduler
job resides. Must be specified if
any triggers are configured to be run on schedule.
EOF
type = "string"
}
terraform_root = {
description = <<EOF
Path of the directory relative to the repo root containing the Terraform configs.
Do not include ending "/".
EOF
type = "string"
}
grant_automation_billing_user_role = {
description = <<EOF
Whether or not to grant automation service account the billing.user role.
Default to true.
EOF
type = "boolean"
}
service_account = {
description = <<EOF
The custom service account to run Cloud Build triggers.
During the CICD deployment, this service account will be granted
all necessary permissions to provision and manage your infrastructure.
See <https://cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts#permissions>
for more details.
EOF
type = "object"
additionalProperties = false
required = [
"id",
]
properties = {
id = {
description = "ID of the service account."
type = "string"
}
exists = {
description = "Whether the service account exists. Defaults to 'false'."
type = "boolean"
}
}
}
logs_bucket = {
description = <<EOF
Name of the Google Cloud Storage bucket where Cloud Build logs should be written.
The bucket will be created as part of CICD.
EOF
type = "string"
}
storage_location = {
description = "Location of logs bucket."
type = "string"
}
envs = {
description = <<EOF
Config block for per-environment resources.
EOF
type = "array"
items = {
type = "object"
additionalProperties = false
required = [
"name",
"branch_name",
"triggers",
]
properties = {
name = {
description = <<EOF
Name of the environment.
EOF
type = "string"
}
branch_name = {
description = <<EOF
Name of the branch to set the Cloud Build Triggers to monitor.
Regex is not supported to enforce a 1:1 mapping from a branch to a GCP
environment.
EOF
type = "string"
}
managed_dirs = {
description = <<EOF
List of root modules managed by the CICD relative to `terraform_root`.
NOTE: The modules will be deployed in the given order. If a module
depends on another module, it should show up after it in this list.
NOTE: The CICD has permission to update APIs within its own project.
Thus, you can list the devops module as one of the managed modules.
Other changes to the devops project or CICD pipelines must be deployed
manually.
EOF
type = "array"
items = {
type = "string"
}
}
triggers = {
description = <<EOF
Config block for the CICD Cloud Build triggers.
EOF
type = "object"
additionalProperties = false
properties = {
validate = {
description = <<EOF
Config block for the presubmit validation Cloud Build trigger. If specified, create
the trigger and grant the Cloud Build Service Account necessary permissions to
perform the build.
EOF
type = "object"
additionalProperties = false
properties = {
run_on_push = {
description = <<EOF
Whether or not to be automatically triggered from a PR/push to branch.
Default to true.
EOF
type = "boolean"
}
run_on_schedule = {
description = <<EOF
Whether or not to be automatically triggered according a specified schedule.
The schedule is specified using [unix-cron format](https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules#defining_the_job_schedule)
at Eastern Standard Time (EST). Default to none.
EOF
type = "string"
}
}
}
plan = {
description = <<EOF
Config block for the presubmit plan Cloud Build trigger.
If specified, create the trigger and grant the Cloud Build Service Account
necessary permissions to perform the build.
EOF
type = "object"
additionalProperties = false
properties = {
run_on_push = {
description = <<EOF
Whether or not to be automatically triggered from a PR/push to branch.
Default to true.
EOF
type = "boolean"
}
run_on_schedule = {
description = <<EOF
Whether or not to be automatically triggered according a specified schedule.
The schedule is specified using [unix-cron format](https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules#defining_the_job_schedule)
at Eastern Standard Time (EST). Default to none.
EOF
type = "string"
}
}
}
apply = {
description = <<EOF
Config block for the postsubmit apply/deployyemt Cloud Build trigger.
If specified,create the trigger and grant the Cloud Build Service Account
necessary permissions to perform the build.
EOF
type = "object"
additionalProperties = false
properties = {
run_on_push = {
description = <<EOF
Whether or not to be automatically triggered from a PR/push to branch.
Default to true.
EOF
type = "boolean"
}
run_on_schedule = {
description = <<EOF
Whether or not to be automatically triggered according a specified schedule.
The schedule is specified using [unix-cron format](https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules#defining_the_job_schedule)
at Eastern Standard Time (EST). Default to none.
EOF
type = "string"
}
}
}
}
}
worker_pool = {
description = <<EOF
Optional Cloud Build private worker pool configuration.
Required for CICD to access resources in a private network, e.g. GKE clusters with a private endpoint.
EOF
type = "object"
additionalProperties = false
required = [
"project",
"location",
"name"
]
properties = {
project = {
description = "The project worker pool belongs."
type = "string"
}
location = {
description = "GCP region of the worker pool. Example: us-central1."
type = "string"
}
name = {
description = "Name of the worker pool."
type = "string"
}
}
}
}
}
}
terraform_addons = {
description = <<EOF
Additional Terraform configuration for the cicd deployment.
For schema see ./deployment.hcl.
EOF
}
}
}
template "deployment" {
recipe_path = "./deployment.hcl"
passthrough = [
"terraform_addons",
]
}
template "cicd" {
component_path = "../components/cicd"
}