Skip to content

Commit 31fdcf9

Browse files
author
Mykhailo Babych
committed
feat: Multiple users in allowed_to_* blocks
1 parent 3650fe7 commit 31fdcf9

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

main.tf

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,22 @@ resource "gitlab_branch_protection" "this" {
12971297

12981298
# Dynamic blocks for allowed_to_push
12991299
dynamic "allowed_to_push" {
1300-
for_each = lookup(each.value.branch, "allowed_to_push", [])
1300+
for_each = flatten([
1301+
for entry in lookup(each.value.branch, "allowed_to_push", []) : (
1302+
contains(keys(entry), "user_emails") ? [
1303+
for email in entry.user_emails : {
1304+
user_email = email
1305+
}
1306+
] :
1307+
contains(keys(entry), "user_email") ? [{
1308+
user_email = entry.user_email
1309+
}] :
1310+
contains(keys(entry), "group") ? [{
1311+
group = entry.group
1312+
}] : []
1313+
)
1314+
])
1315+
13011316
content {
13021317
user_id = contains(keys(local.exists_users), lookup(allowed_to_push.value, "user_email", "")) ? local.exists_users[allowed_to_push.value.user_email].id : null
13031318
group_id = contains(keys(local.exists_groups), lookup(allowed_to_push.value, "group", "")) ? local.exists_groups[allowed_to_push.value.group][0].group_id : null
@@ -1306,7 +1321,22 @@ resource "gitlab_branch_protection" "this" {
13061321

13071322
# Dynamic blocks for allowed_to_merge
13081323
dynamic "allowed_to_merge" {
1309-
for_each = lookup(each.value.branch, "allowed_to_merge", [])
1324+
for_each = flatten([
1325+
for entry in lookup(each.value.branch, "allowed_to_merge", []) : (
1326+
contains(keys(entry), "user_emails") ? [
1327+
for email in entry.user_emails : {
1328+
user_email = email
1329+
}
1330+
] :
1331+
contains(keys(entry), "user_email") ? [{
1332+
user_email = entry.user_email
1333+
}] :
1334+
contains(keys(entry), "group") ? [{
1335+
group = entry.group
1336+
}] : []
1337+
)
1338+
])
1339+
13101340
content {
13111341
user_id = contains(keys(local.exists_users), lookup(allowed_to_merge.value, "user_email", "")) ? local.exists_users[allowed_to_merge.value.user_email].id : null
13121342
group_id = contains(keys(local.exists_groups), lookup(allowed_to_merge.value, "group", "")) ? local.exists_groups[allowed_to_merge.value.group][0].group_id : null
@@ -1315,7 +1345,22 @@ resource "gitlab_branch_protection" "this" {
13151345

13161346
# Dynamic blocks for allowed_to_unprotect
13171347
dynamic "allowed_to_unprotect" {
1318-
for_each = lookup(each.value.branch, "allowed_to_unprotect", [])
1348+
for_each = flatten([
1349+
for entry in lookup(each.value.branch, "allowed_to_unprotect", []) : (
1350+
contains(keys(entry), "user_emails") ? [
1351+
for email in entry.user_emails : {
1352+
user_email = email
1353+
}
1354+
] :
1355+
contains(keys(entry), "user_email") ? [{
1356+
user_email = entry.user_email
1357+
}] :
1358+
contains(keys(entry), "group") ? [{
1359+
group = entry.group
1360+
}] : []
1361+
)
1362+
])
1363+
13191364
content {
13201365
user_id = contains(keys(local.exists_users), lookup(allowed_to_unprotect.value, "user_email", "")) ? local.exists_users[allowed_to_unprotect.value.user_email].id : null
13211366
group_id = contains(keys(local.exists_groups), lookup(allowed_to_unprotect.value, "group", "")) ? local.exists_groups[allowed_to_unprotect.value.group][0].group_id : null

0 commit comments

Comments
 (0)