From 09e9f48f7af3a6b4e160b701f50941895c5ff4ec Mon Sep 17 00:00:00 2001 From: Alex Talbot Date: Tue, 29 Apr 2025 06:59:43 +0000 Subject: [PATCH 1/2] fix: Merge Managed and Unmanaged Users - The input variable `existing_sso_users`, while present, was previsously unused. This includes it into a new merged collection that then updates managed as well as unmanaged user memberships. --- locals.tf | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/locals.tf b/locals.tf index d996c3d..b8bb406 100644 --- a/locals.tf +++ b/locals.tf @@ -1,10 +1,13 @@ # - Users and Groups - locals { - # Create a new local variable by flattening the complex type given in the variable "sso_users" + # To support both managed and federated identities, let's combine the two user collections. + sso_users = merge(var.sso_users, var.existing_sso_users) + + # Create a new local variable by flattening the complex type given in the local aggregated variable "sso_users" flatten_user_data = flatten([ - for this_user in keys(var.sso_users) : [ - for group in var.sso_users[this_user].group_membership : { - user_name = var.sso_users[this_user].user_name + for this_user in keys(local.sso_users) : [ + for group in local.sso_users[this_user].group_membership : { + user_name = local.sso_users[this_user].user_name group_name = group } ] From 7b79d51b1804458ecc7744bb2e5071b1b1b91806 Mon Sep 17 00:00:00 2001 From: Alex Talbot Date: Sat, 10 May 2025 18:25:09 +0100 Subject: [PATCH 2/2] fix: Add empty collection defaults - Add coalesce to merges so as to provide default empty collections so avoiding null-based lookup/reference errors. --- locals.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locals.tf b/locals.tf index b8bb406..58c5448 100644 --- a/locals.tf +++ b/locals.tf @@ -1,13 +1,13 @@ # - Users and Groups - locals { # To support both managed and federated identities, let's combine the two user collections. - sso_users = merge(var.sso_users, var.existing_sso_users) + sso_users = merge(coalesce(var.sso_users, {}), coalesce(var.existing_sso_users, {})) - # Create a new local variable by flattening the complex type given in the local aggregated variable "sso_users" + # Create a new local variable by flattening the complex type given in the variable "sso_users" flatten_user_data = flatten([ - for this_user in keys(local.sso_users) : [ - for group in local.sso_users[this_user].group_membership : { - user_name = local.sso_users[this_user].user_name + for this_user, user_data in local.sso_users : [ + for group in coalesce(user_data.group_membership, []) : { + user_name = user_data.user_name group_name = group } ]