From f4660da8cc203a6ed37e333415ab36b2c583cf09 Mon Sep 17 00:00:00 2001 From: Emerson Barros Date: Thu, 22 Dec 2022 23:28:19 -0300 Subject: [PATCH 1/2] fix: change count for for_each into ram_principal_association resource and adjust the output related to this resource --- main.tf | 4 ++-- outputs.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 600e26e..a38a29a 100644 --- a/main.tf +++ b/main.tf @@ -161,9 +161,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 = var.create_tgw && var.share_tgw ? toset(var.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] } From ea24b35f3244e15d193bb9889da70a28c19481e2 Mon Sep 17 00:00:00 2001 From: Emerson Barros Date: Sun, 12 Feb 2023 18:51:16 -0300 Subject: [PATCH 2/2] fix: create a local value in order to avoid failure on for_each by computed values --- main.tf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a38a29a..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,7 +164,7 @@ resource "aws_ram_resource_association" "this" { } resource "aws_ram_principal_association" "this" { - for_each = var.create_tgw && var.share_tgw ? toset(var.ram_principals) : [] + for_each = local.ram_principals principal = each.value resource_share_arn = aws_ram_resource_share.this[0].arn