Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing support for existing_sso_users #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ No modules.
| [aws_identitystore_group.sso_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/identitystore_group) | resource |
| [aws_identitystore_group_membership.sso_group_membership](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/identitystore_group_membership) | resource |
| [aws_identitystore_group_membership.sso_group_membership_existing_google_sso_users](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/identitystore_group_membership) | resource |
| [aws_identitystore_group_membership.sso_group_membership_existing_sso_users](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/identitystore_group_membership) | resource |
| [aws_identitystore_user.sso_users](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/identitystore_user) | resource |
| [aws_ssoadmin_account_assignment.account_assignment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_account_assignment) | resource |
| [aws_ssoadmin_application.sso_apps](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_application) | resource |
Expand Down
14 changes: 14 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ locals {
for s in local.flatten_user_data : format("%s_%s", s.user_name, s.group_name) => s
}

# Create a new local variable by flattening the complex type given in the variable "existing_sso_users"
flatten_user_data_existing_sso_users = flatten([
for this_existing_user in keys(var.existing_sso_users) : [
for group in var.existing_sso_users[this_existing_user].group_membership : {
user_name = var.existing_sso_users[this_existing_user].user_name
group_name = group
}
]
])

users_and_their_groups_existing_sso_users = {
for s in local.flatten_user_data_existing_sso_users : format("%s_%s", s.user_name, s.group_name) => s
}

# Create a new local variable by flattening the complex type given in the variable "existing_google_sso_users"
flatten_user_data_existing_google_sso_users = flatten([
for this_existing_google_user in keys(var.existing_google_sso_users) : [
Expand Down
12 changes: 11 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ resource "aws_identitystore_group_membership" "sso_group_membership" {
identity_store_id = local.sso_instance_id

group_id = (contains(local.this_groups, each.value.group_name) ? aws_identitystore_group.sso_groups[each.value.group_name].group_id : data.aws_identitystore_group.existing_sso_groups[each.value.group_name].group_id)
member_id = (contains(local.this_users, each.value.user_name) ? aws_identitystore_user.sso_users[each.value.user_name].user_id : data.aws_identitystore_user.existing_sso_users[each.value.user_name].user_id)
member_id = aws_identitystore_user.sso_users[each.value.user_name].user_id

}

# Existing Users with New Groups
resource "aws_identitystore_group_membership" "sso_group_membership_existing_sso_users" {
for_each = local.users_and_their_groups_existing_sso_users
identity_store_id = local.sso_instance_id

group_id = (contains(local.this_groups, each.value.group_name) ? aws_identitystore_group.sso_groups[each.value.group_name].group_id : data.aws_identitystore_group.existing_sso_groups[each.value.group_name].group_id)
member_id = data.aws_identitystore_user.existing_sso_users[each.value.user_name].user_id

}

Expand Down