diff --git a/main.tf b/main.tf index 600e26e..4dd5c70 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,7 @@ locals { + # Store the list of principals and convert to set + ram_principals = var.create_tgw && var.share_tgw ? toset(var.ram_principals) : [] + # List of maps with key and route values vpc_attachments_with_routes = chunklist(flatten([ for k, v in var.vpc_attachments : setproduct([{ key = k }], v.tgw_routes) if var.create_tgw && can(v.tgw_routes) @@ -161,9 +164,9 @@ resource "aws_ram_resource_association" "this" { } resource "aws_ram_principal_association" "this" { - count = var.create_tgw && var.share_tgw ? length(var.ram_principals) : 0 + for_each = local.ram_principals - principal = var.ram_principals[count.index] + principal = each.value resource_share_arn = aws_ram_resource_share.this[0].arn } diff --git a/outputs.tf b/outputs.tf index 8dcb8a5..94223ef 100644 --- a/outputs.tf +++ b/outputs.tf @@ -96,5 +96,5 @@ output "ram_resource_share_id" { output "ram_principal_association_id" { description = "The Amazon Resource Name (ARN) of the Resource Share and the principal, separated by a comma" - value = try(aws_ram_principal_association.this[0].id, "") + value = [for k, v in aws_ram_principal_association.this : v.id] }