-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.tf
More file actions
186 lines (151 loc) · 5.75 KB
/
Copy pathmain.tf
File metadata and controls
186 lines (151 loc) · 5.75 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
resource "github_repository" "this" {
name = var.repo_name
description = var.repo_config.description
visibility = var.repo_config.visibility
vulnerability_alerts = var.repo_config.vulnerability_alerts
allow_auto_merge = var.repo_config.allow_auto_merge
allow_merge_commit = var.repo_config.allow_merge_commit
allow_rebase_merge = var.repo_config.allow_rebase_merge
allow_squash_merge = var.repo_config.allow_squash_merge
allow_update_branch = var.repo_config.allow_update_branch
archive_on_destroy = var.repo_config.archive_on_destroy
auto_init = var.repo_config.auto_init
delete_branch_on_merge = var.repo_config.delete_branch_on_merge
has_discussions = var.repo_config.has_discussions
has_issues = var.repo_config.has_issues
has_projects = var.repo_config.has_projects
has_wiki = var.repo_config.has_wiki
web_commit_signoff_required = var.repo_config.web_commit_signoff_required
dynamic "pages" {
for_each = var.repo_config.pages != null ? [1] : []
content {
build_type = var.repo_config.pages.build_type
cname = var.repo_config.pages.cname
dynamic "source" {
for_each = var.repo_config.pages.source != null ? [1] : []
content {
branch = var.repo_config.pages.source.branch
path = var.repo_config.pages.source.path
}
}
}
}
}
resource "github_branch" "this" {
for_each = var.repo_config.branches
repository = github_repository.this.name
branch = each.key
source_branch = var.organization_default_branch
}
resource "github_branch_default" "this" {
repository = github_repository.this.name
branch = github_branch.this[var.repo_config.default_branch].branch
}
resource "github_repository_collaborator" "this" {
for_each = {
for user, perm in var.repo_config.users : user => {
user = user
perm = perm
}
}
repository = github_repository.this.name
username = each.value.user
permission = each.value.perm
}
resource "github_team_repository" "this" {
for_each = {
for team, perm in var.repo_config.teams : team => {
team = team
perm = perm
}
}
team_id = can(tonumber(each.value.team)) ? each.value.team : data.github_team.this[each.value.team].id
repository = github_repository.this.name
permission = each.value.perm
}
resource "github_repository_file" "branch_file" {
for_each = {
for branch_name, _ in var.repo_config.branches : branch_name => {
branch = branch_name
file = var.repo_config.branch_file
} if var.repo_config.branch_file_enabled
}
repository = github_repository.this.name
branch = github_branch.this[each.key].branch
file = each.value.file
content = "${github_branch.this[each.key].branch}\n"
commit_message = "Managed by Terraform (github_repo: branch_file ${each.value.file})"
depends_on = [github_branch_protection.this]
}
resource "github_branch_protection" "this" {
for_each = {
for branch_name, branch_config in var.repo_config.branches : branch_name => merge(
branch_config,
{
branch = branch_name
enforce_admins = var.enforce_admins_enabled ? branch_config.enforce_admins : false
}
) if branch_config.branch_protection_enabled
}
repository_id = github_repository.this.node_id # Use of `node_id` instead of `id` or `name` is a workaround for terraform import, see https://github.com/integrations/terraform-provider-github/issues/622
pattern = each.value.branch
enforce_admins = each.value.enforce_admins
allows_deletions = each.value.allow_deletions
allows_force_pushes = each.value.allow_force_pushes
require_conversation_resolution = each.value.require_conversation_resolution
dynamic "required_pull_request_reviews" {
for_each = each.value.required_pull_request_reviews_enabled ? [1] : []
content {
dismiss_stale_reviews = each.value.dismiss_stale_reviews
required_approving_review_count = each.value.required_approving_review_count
require_code_owner_reviews = each.value.require_code_owner_reviews
}
}
dynamic "required_status_checks" {
for_each = each.value.required_status_checks_enabled ? [1] : []
content {
strict = each.value.required_status_checks.strict
contexts = each.value.required_status_checks.contexts
}
}
}
resource "github_repository_autolink_reference" "this" {
count = var.repo_config.autolink != null ? 1 : 0
repository = github_repository.this.name
key_prefix = var.repo_config.autolink.key_prefix
target_url_template = var.repo_config.autolink.url_template
}
resource "github_app_installation_repository" "this" {
for_each = var.repo_config.apps
installation_id = each.value.installation_id
repository = github_repository.this.name
}
data "github_team" "this" {
for_each = toset([for team, _ in var.repo_config.teams : team if !can(tonumber(team))])
slug = each.key
summary_only = true
}
resource "github_repository_deploy_key" "this" {
for_each = {
for deploy_key in var.repo_config.deploy_keys : deploy_key.title => {
title = deploy_key.title
key = deploy_key.key
read_only = deploy_key.read_only
}
}
repository = github_repository.this.name
title = each.value.title
key = each.value.key
read_only = each.value.read_only
}
resource "github_actions_secret" "this" {
for_each = {
for name, value in var.repo_config.secrets : name => {
name = name
value = value
}
}
repository = github_repository.this.name
secret_name = each.value.name
plaintext_value = each.value.value
}