-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvariables.tf
More file actions
690 lines (602 loc) · 24.1 KB
/
variables.tf
File metadata and controls
690 lines (602 loc) · 24.1 KB
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
variable "description" {
description = "Description of the repository"
type = string
default = null
}
variable "visibility" {
description = "Visibility of the repository. Must be public, private, or internal."
type = string
default = "public"
validation {
condition = contains(["public", "private", "internal"], var.visibility)
error_message = "Repository visibility must be public, private or internal"
}
}
variable "homepage_url" {
description = "Homepage URL of the repository"
type = string
default = null
}
variable "template" {
description = "Template repository"
type = object({
owner = string
name = string
include_all_branches = optional(bool, false)
})
default = null
}
variable "fork" {
description = "Configuration for forking an existing repository"
type = object({
source_owner = string
source_repo = string
})
default = null
}
variable "archived" {
description = "Whether the repository is archived"
type = bool
default = false
}
variable "has_issues" {
description = "Whether the repository has issues enabled"
type = bool
default = false
}
variable "has_projects" {
description = "Whether the repository has projects enabled"
type = bool
default = false
}
variable "has_discussions" {
description = "Whether the repository has discussions enabled"
type = bool
default = false
}
variable "has_wiki" {
description = "Whether the repository has wiki enabled"
type = bool
default = false
}
variable "is_template" {
description = "Whether the repository is a template"
type = bool
default = false
}
variable "allow_auto_merge" {
description = "Allow auto merge"
type = bool
default = false
}
variable "allow_squash_merge" {
description = "Allow squash merge"
type = bool
default = true
}
variable "squash_merge_commit_title" {
description = "Squash merge commit title. Must be PR_TITLE or COMMIT_OR_PR_TITLE."
type = string
default = "PR_TITLE"
validation {
condition = contains(["PR_TITLE", "COMMIT_OR_PR_TITLE"], var.squash_merge_commit_title)
error_message = "Repository squash merge commit title must be PR_TITLE, COMMIT_OR_PR_TITLE"
}
}
variable "squash_merge_commit_message" {
description = "Squash merge commit message. Must be PR_BODY, COMMIT_MESSAGES or BLANK."
type = string
default = "COMMIT_MESSAGE"
validation {
condition = contains(["PR_BODY", "COMMIT_MESSAGES", "BLANK"], var.squash_merge_commit_message)
error_message = "Repository squash merge commit message must be PR_BODY, COMMIT_MESSAGES or BLANK"
}
}
variable "allow_merge_commit" {
description = "Allow merge commit"
type = bool
default = true
}
variable "merge_commit_title" {
description = "Merge commit title. Must be PR_TITLE or MERGE_MESSAGE."
type = string
default = "PR_TITLE"
validation {
condition = contains(["PR_TITLE", "MERGE_MESSAGE"], var.merge_commit_title)
error_message = "Repository merge commit title must be PR_TITLE, MERGE_MESSAGE"
}
}
variable "merge_commit_message" {
description = "Merge commit message. Must be PR_BODY, PR_TITLE or BLANK."
type = string
default = "PR_BODY"
validation {
condition = contains(["PR_BODY", "PR_TITLE", "BLANK"], var.merge_commit_message)
error_message = "Repository merge commit message must be PR_BODY, PR_TITLE or BLANK"
}
}
variable "allow_rebase_merge" {
description = "Allow rebase merge"
type = bool
default = true
}
variable "delete_branch_on_merge" {
description = "Delete branch on merge"
type = bool
default = false
}
variable "default_branch" {
description = "Default branch name"
type = string
default = "main"
}
variable "web_commit_signoff_required" {
description = "Require signoff on web commits"
type = bool
default = false
}
variable "topics" {
description = "List of repository topics"
type = list(string)
default = []
}
variable "license_template" {
description = "License template"
type = string
default = null
}
variable "gitignore_template" {
description = "Gitignore template"
type = string
default = null
}
variable "auto_init" {
description = "Auto-initialize the repository"
type = bool
default = false
}
variable "enable_vulnerability_alerts" {
description = "Enable vulnerability alerts"
type = bool
default = true
}
variable "allow_update_branch" {
description = "Allow updating the branch"
type = bool
default = false
}
variable "security_and_analysis" {
description = "Security and analysis settings"
type = object({
advanced_security = optional(bool, false)
code_security = optional(bool, false)
secret_scanning = optional(bool, false)
secret_scanning_push_protection = optional(bool, false)
secret_scanning_ai_detection = optional(bool, false)
secret_scanning_non_provider_patterns = optional(bool, false)
})
default = null
}
variable "pages" {
description = "GitHub Pages configuration for the repository"
type = object({
source = optional(object({
branch = string
path = optional(string, "/")
}), null)
build_type = optional(string, "workflow")
cname = optional(string, null)
})
default = null
validation {
condition = var.pages == null || try(contains(["legacy", "workflow"], var.pages.build_type), true)
error_message = "Pages build_type must be 'legacy' or 'workflow'"
}
}
variable "archive_on_destroy" {
description = "Archive the repository on destroy"
type = bool
default = false
}
variable "autolink_references" {
description = "Autolink references"
type = map(object({
key_prefix = string
target_url_template = string
is_alphanumeric = optional(bool, false)
}))
default = {}
nullable = false
validation {
condition = alltrue([for k, v in var.autolink_references : can(regex("^http(s)?://", v.target_url_template))])
error_message = "Autolink reference target URL template must start with http:// or https://"
}
validation {
condition = alltrue([for k, v in var.autolink_references : can(strcontains(v.key_prefix, "<num>"))])
error_message = "Autolink reference key prefix must contain <num>"
}
}
variable "custom_properties" {
description = "Custom properties for the repository"
type = map(object({
string = optional(string, null)
boolean = optional(bool, null)
single_select = optional(string, null)
multi_select = optional(list(string), null)
}))
default = {}
nullable = false
validation {
condition = alltrue([for k, v in var.custom_properties : length([for n, i in v : n if i != null]) == 1])
error_message = "Custom property must have only one of the following: string, boolean, single_select, multi_select"
}
}
variable "environments" {
description = "Environments for the repository. Enviroment secrets should be encrypted using the GitHub public key in Base64 format if prefixed with nacl:. Read more: https://docs.github.com/en/actions/security-for-github-actions/encrypted-secrets"
type = map(object({
wait_timer = optional(number, 0)
can_admins_bypass = optional(bool, false)
prevent_self_review = optional(bool, false)
reviewers = optional(object({
teams = optional(list(string), [])
users = optional(list(string), [])
}), null)
deployment_branch_policy = optional(object({
protected_branches = optional(bool, false)
custom_branches = optional(object({
branches = optional(list(string), null)
tags = optional(list(string), null)
}), null)
}), null)
variables = optional(map(string), null)
secrets = optional(map(string), null)
}))
default = {}
sensitive = true
nullable = false
validation {
condition = alltrue([for k, v in var.environments : try(length(v.reviewers.teams) <= 6, true)])
error_message = "Environment reviewers can not have more than 6 teams"
}
validation {
condition = alltrue([for k, v in var.environments : try(length(v.reviewers.users) <= 6, true)])
error_message = "Environment reviewers can not have more than 6 users"
}
validation {
condition = alltrue([for k, v in var.environments : try(v.deployment_branch_policy.protected_branches == true || v.deployment_branch_policy.custom_branches != null, true)])
error_message = "Environment deployment branch policy should have protected_branches set to true or custom_branches specified"
}
validation {
condition = alltrue([for k, v in var.environments : try(alltrue([for k, v in v.variables : can(regex("^[a-zA-Z0-9_]+$", k))]), true)])
error_message = "Environment variables must be alphanumeric and underscores only, can not start with a number"
}
validation {
condition = alltrue([for k, v in var.environments : try(alltrue([for k, v in v.secrets : can(regex("^[a-zA-Z0-9_]+$", k))]), true)])
error_message = "Environment secrets must be alphanumeric and underscores only, can not start with a number"
}
}
variable "variables" {
description = "Environment variables for the repository"
type = map(string)
default = {}
nullable = false
validation {
condition = var.variables == null || alltrue([for k, v in var.variables : can(regex("^[a-zA-Z0-9_]+$", k))])
error_message = "Variable names must be alphanumeric and underscores only, can not start with a number"
}
}
variable "secrets" {
description = "Secrets for the repository (if prefixed with nacl: it should be encrypted value using the GitHub public key in Base64 format. Read more: https://docs.github.com/en/actions/security-for-github-actions/encrypted-secrets)"
type = map(string)
default = {}
sensitive = true
nullable = false
validation {
condition = var.secrets == null || alltrue([for k, v in var.secrets : can(regex("^[a-zA-Z0-9_]+$", k))])
error_message = "Secret names must be alphanumeric and underscores only, can not start with a number"
}
}
variable "deploy_keys" {
description = "Deploy keys for the repository"
type = map(object({
title = string
key = string
read_only = optional(bool, false)
}))
default = {}
nullable = false
}
// https://docs.github.com/en/webhooks/webhook-events-and-payloads
variable "webhooks" {
description = "A map of webhooks to configure for the repository"
type = map(object({
active = optional(bool, true)
events = list(string)
url = string
content_type = optional(string, "json")
insecure_ssl = optional(bool, false)
secret = optional(string, null)
}))
default = {}
nullable = false
validation {
condition = alltrue([for k, v in var.webhooks : can(regex("^http(s)?://", v.url))])
error_message = "Webhook URL must start with http:// or https://"
}
validation {
condition = alltrue([for k, v in var.webhooks : contains(["json", "form"], v.content_type)])
error_message = "Webhook content type must be json or form"
}
}
variable "labels" {
description = "A map of labels to configure for the repository"
type = map(object({
color = string
description = string
}))
default = {}
nullable = false
}
variable "teams" {
description = "A map of teams and their permissions for the repository. This will create github_repository_collaborators resources for each team "
type = map(string)
default = {}
nullable = false
}
variable "team_repository" {
description = "A map of permissions and their teams for the repository. This will create github_team_repository resources for each team. Format: { permission = [list of teams] }"
type = map(list(string))
default = {}
nullable = false
validation {
condition = alltrue([for permission, teams in var.team_repository : contains(["pull", "triage", "push", "maintain", "admin"], permission)])
error_message = "Team repository permissions must be one of: pull, triage, push, maintain, admin"
}
}
variable "users" {
description = "A map of users and their permissions for the repository"
type = map(string)
default = {}
nullable = false
}
variable "organization_repository_roles_enabled" {
description = "Whether to use organization repository roles."
type = bool
default = false
}
variable "rulesets" {
description = "A map of rulesets to configure for the repository"
type = map(object({
name = string
// disabled, active, evaluate
enforcement = string
// branch, tag, push
target = string
bypass_actors = optional(list(object({
// always, pull_request, exempt
bypass_mode = string
actor_id = optional(string, null)
// RepositoryRole, Team, Integration, OrganizationAdmin, DeployKey
actor_type = string
})), [])
// conditions is required for branch and tag rulesets, but not supported for push rulesets
conditions = optional(object({
ref_name = object({
// Supports ~DEFAULT_BRANCH or ~ALL
include = optional(list(string), [])
exclude = optional(list(string), [])
})
}), null)
rules = object({
branch_name_pattern = optional(object({
// starts_with, ends_with, contains, regex
operator = string
pattern = string
name = optional(string, null)
negate = optional(bool, false)
}), null),
commit_author_email_pattern = optional(object({
// starts_with, ends_with, contains, regex
operator = string
pattern = string
name = optional(string, null)
negate = optional(bool, false)
}), null),
creation = optional(bool, false),
deletion = optional(bool, false),
non_fast_forward = optional(bool, false),
required_linear_history = optional(bool, false),
required_signatures = optional(bool, false),
update = optional(bool, false),
update_allows_fetch_and_merge = optional(bool, false),
required_pull_request_reviews = optional(object({
dismiss_stale_reviews = bool
required_approving_review_count = number
}), null),
commit_message_pattern = optional(object({
// starts_with, ends_with, contains, regex
operator = string
pattern = string
name = optional(string, null)
negate = optional(bool, false)
}), null),
committer_email_pattern = optional(object({
// starts_with, ends_with, contains, regex
operator = string
pattern = string
name = optional(string, null)
negate = optional(bool, false)
}), null),
merge_queue = optional(object({
check_response_timeout_minutes = optional(number, 60)
// ALLGREEN, HEADGREEN
grouping_strategy = string
max_entries_to_build = optional(number, 5)
max_entries_to_merge = optional(number, 5)
// MERGE, SQUASH, REBASE
merge_method = optional(string, "MERGE")
min_entries_to_merge = optional(number, 1)
min_entries_to_merge_wait_minutes = optional(number, 5)
}), null),
pull_request = optional(object({
dismiss_stale_reviews_on_push = optional(bool, false)
require_code_owner_review = optional(bool, false)
require_last_push_approval = optional(bool, false)
required_approving_review_count = optional(number, 0)
required_review_thread_resolution = optional(bool, false)
}), null),
required_deployments = optional(object({
required_deployment_environments = optional(list(string), [])
}), null),
required_status_checks = optional(object({
required_check = list(object({
context = string
integration_id = optional(number, null)
}))
strict_required_status_checks_policy = optional(bool, false)
do_not_enforce_on_create = optional(bool, false)
}), null),
tag_name_pattern = optional(object({
// starts_with, ends_with, contains, regex
operator = string
pattern = string
name = optional(string, null)
negate = optional(bool, false)
}), null),
required_code_scanning = optional(object({
required_code_scanning_tool = list(object({
// none, errors, errors_and_warnings, all
alerts_threshold = string
// none, critical, high_or_higher, medium_or_higher, all
security_alerts_threshold = string
tool = string
}))
}), null),
copilot_code_review = optional(object({
review_on_push = optional(bool, false)
review_draft_pull_requests = optional(bool, false)
}), null),
// Push ruleset rules (only valid when target = "push")
file_path_restriction = optional(object({
restricted_file_paths = list(string)
}), null),
max_file_size = optional(object({
// 1-100 MB
max_file_size = number
}), null),
max_file_path_length = optional(object({
max_file_path_length = number
}), null),
file_extension_restriction = optional(object({
restricted_file_extensions = list(string)
}), null),
}),
}))
default = {}
validation {
condition = alltrue([for k, v in var.rulesets : can(regex("^[a-zA-Z0-9_]+$", k))])
error_message = "Ruleset names must be alphanumeric and underscores only, can not start with a number"
}
validation {
condition = alltrue([for k, v in var.rulesets : contains(["disabled", "active", "evaluate"], v.enforcement)])
error_message = "Ruleset enforcement must be disabled, active, or evaluate"
}
validation {
condition = alltrue([for k, v in var.rulesets : contains(["branch", "tag", "push"], v.target)])
error_message = "Ruleset target must be branch, tag, or push"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["always", "pull_request", "exempt"], v.bypass_actors.bypass_mode), true)])
error_message = "Ruleset bypass mode must be always, pull_request, or exempt"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey"], v.bypass_actors.actor_type), true)])
error_message = "Ruleset actor type must be RepositoryRole, Team, Integration, OrganizationAdmin, or DeployKey"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["starts_with", "ends_with", "contains", "regex"], v.rules.branch_name_pattern.operator), true)])
error_message = "Ruleset branch name pattern operator must be starts_with, ends_with, contains or regex"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "branch" || try(v.rules.branch_name_pattern == null, true)])
error_message = "Ruleset branch name pattern can be specified only for branch rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["starts_with", "ends_with", "contains", "equals", "regex"], v.rules.commit_author_email_pattern.operator), true)])
error_message = "Ruleset commit author email pattern operator must be starts_with, ends_with, contains, equals or regex"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["starts_with", "ends_with", "contains", "equals", "regex"], v.rules.commit_message_pattern.operator), true)])
error_message = "Ruleset commit message pattern operator must be starts_with, ends_with, contains, equals or regex"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["starts_with", "ends_with", "contains", "equals", "regex"], v.rules.committer_email_pattern.operator), true)])
error_message = "Ruleset committer email pattern operator must be starts_with, ends_with, contains, equals or regex"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["ALLGREEN", "HEADGREEN"], v.rules.merge_queue.grouping_strategy), true)])
error_message = "Ruleset merge queue grouping strategy must be ALLGREEN or HEADGREEN"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["MERGE", "SQUASH", "REBASE"], v.rules.merge_queue.merge_method), true)])
error_message = "Ruleset merge queue merge method must be MERGE, SQUASH or REBASE"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.rules.merge_queue == null || alltrue([for c in v.conditions.ref_name.include : can(!strcontains(c, "*") && !strcontains(c, "~ALL"))])])
error_message = "Ruleset merge queue condition mush point to specific branch"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(contains(["starts_with", "ends_with", "contains", "regex"], v.rules.tag_name_pattern.operator), true)])
error_message = "Ruleset branch name pattern operator must be starts_with, ends_with, contains or regex"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "tag" || try(v.rules.tag_name_pattern == null, true)])
error_message = "Ruleset tag name pattern can be specified only for tag rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "push" || v.conditions != null])
error_message = "Ruleset conditions with ref_name is required for branch and tag rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target != "push" || v.conditions == null])
error_message = "Ruleset conditions with ref_name is not supported for push rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "push" || try(v.rules.file_path_restriction == null, true)])
error_message = "Ruleset file_path_restriction can be specified only for push rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "push" || try(v.rules.max_file_size == null, true)])
error_message = "Ruleset max_file_size can be specified only for push rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "push" || try(v.rules.max_file_path_length == null, true)])
error_message = "Ruleset max_file_path_length can be specified only for push rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : v.target == "push" || try(v.rules.file_extension_restriction == null, true)])
error_message = "Ruleset file_extension_restriction can be specified only for push rulesets"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(v.rules.max_file_size.max_file_size >= 1 && v.rules.max_file_size.max_file_size <= 100, true)])
error_message = "Ruleset max_file_size must be between 1 and 100 MB"
}
validation {
condition = alltrue([for k, v in var.rulesets : !v.rules.update_allows_fetch_and_merge || v.rules.update])
error_message = "Ruleset update_allows_fetch_and_merge requires update to be true"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(alltrue([
for tool in v.rules.required_code_scanning.required_code_scanning_tool :
contains(["none", "errors", "errors_and_warnings", "all"], tool.alerts_threshold)
]), true)])
error_message = "Ruleset required_code_scanning alerts_threshold must be none, errors, errors_and_warnings, or all"
}
validation {
condition = alltrue([for k, v in var.rulesets : try(alltrue([
for tool in v.rules.required_code_scanning.required_code_scanning_tool :
contains(["none", "critical", "high_or_higher", "medium_or_higher", "all"], tool.security_alerts_threshold)
]), true)])
error_message = "Ruleset required_code_scanning security_alerts_threshold must be none, critical, high_or_higher, medium_or_higher, or all"
}
}