I’m trying to loop through a list of complex objects with lists of objects inside to find a few specific lists of maps. I’m using local variables to return the lists and then combine them into a single list of maps. I’ve put together some logic but all I’m getting is an empty list of strings, and I can’t figure out where the problem is.
locals {
group_names = distinct([for group in var.existing_groups : group.name])
requestors = [
for ap in var.assignment_policies: ap.requestor_settings.requestor
]
primary_approvers = [
for ap in var.assignment_policies: [
# Primary Approvers
for as in ap.approval_settings.approval_stage: [
as.primary_approver
]
]
]
alternative_approvers = try(
[
for ap in var.assignment_policies: [
# Alternative Approvers
for as in ap.approval_settings.approval_stage: [
as.alternative_approver
]
]
], []
)
approvers = concat(local.primary_approvers, local.alternative_approvers)
requestors_and_approvers = concat(local.requestors, local.approvers)
reviewer_groups = distinct([for object_id, subject_type in local.requestors_and_approvers : object_id if subject_type == "groupMembers"])
reviewer_users = distinct([for object_id, subject_type in local.requestors_and_approvers : object_id if subject_type == "singleUser"])
groups_map = zipmap(data.azuread_groups.reviewer_groups.display_names, data.azuread_groups.reviewer_groups.object_ids)
users_map = zipmap(data.azuread_users.reviewer_users.user_principal_names, data.azuread_users.reviewer_users.object_ids)
reviewers_map = merge(local.groups_map, local.users_map)
}
data "azuread_groups" "reviewer_groups" {
display_names = local.reviewer_groups
}
data "azuread_users" "reviewer_users" {
user_principal_names = local.reviewer_users
}
module "access_package" {
assignment_policies = [
{
requestor_settings = {
requestor = [
{
object_id = "test-grp-3"
subject_type = "groupMembers"
},
{
object_id = "test-grp-4"
subject_type = "groupMembers"
{
]
}
approval_settings = {
approval_stage = [
{
primary_approver = [
{
object_id = "test-grp-5"
subject_type = "groupMembers"
},
{
object_id = "example@example.com"
subject_type = "singleUser"
},
{
object_id = "example2@example.com"
subject_type = "singleUser"
}
]
alternative_approver = [
{
object_id = "test-grp-6"
subject_type = "groupMembers"
},
{
object_id = "example3@example.com"
subject_type = "singleUser"
},
{
object_id = "example4@example.com"
subject_type = "singleUser"
}
]
}
]
}
}
]
}
I tried running terraform plan
with the above code but got the following:
local.reviewers_map is empty map of string