Hello guys hope you are all well, has the title says i want to know if it’s possible to convert a map to a string but only for a specific resource this is my code:
main.tf
module "groups" {
source = "../../Groups/module/module"
groups = {
security_tooling_prod = {
group = "some group"
users = ["user1", "user2"]
}
}
}
variables.tf inside module
variable "groups" {
type = map(any)
}
module.tf
data "aws_ssoadmin_instances" "this" {}
data "aws_identitystore_user" "this" {
for_each = local.users
identity_store_id = local.ssoadmin_instance_id
alternate_identifier {
unique_attribute {
attribute_path = "UserName"
attribute_value = each.value
}
}
}
resource "aws_identitystore_group" "this" {
for_each = var.groups
display_name = "aws-outcloud-${replace(lower(each.value.group), "/\\s+/", "-")}"
identity_store_id = local.ssoadmin_instance_id
}
resource "aws_identitystore_group_membership" "this" {
for_each = var.groups
identity_store_id = local.ssoadmin_instance_id
group_id = aws_identitystore_group.this[each.key].group_id
member_id = data.aws_identitystore_user.this[each.key].user_id
}
local.tf
locals {
ssoadmin_instance_id = tolist(data.aws_ssoadmin_instances.this.identity_store_ids)[0]
users = toset([for k , v in var.groups : v.users]...)
}
In data.aws_identitystore_user.this I need to change my list of users to a string for each value in the list, i think i managed to do that using the locals but it creates a new error:
│ Error: Invalid index
│
│ on ../../Groups/module/module/main.tf line 26, in resource "aws_identitystore_group_membership" "this":
│ 26: member_id = data.aws_identitystore_user.this[each.key].user_id
│ ├────────────────
│ │ data.aws_identitystore_user.this is object with 2 attributes
│ │ each.key is "security_tooling_prod"
│
│ The given key does not identify an element in this collection value.
Can someone please explain to me what am i doing wrong?
Thank you in advance!