From 53fe2de5e5b2fa83cf0c531bc34933de457110a3 Mon Sep 17 00:00:00 2001 From: Tammy Tsang Date: Fri, 11 Oct 2024 22:12:06 +0800 Subject: [PATCH] fix: prevent lambda IAM policies from detaching when orders are swapped --- iam.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iam.tf b/iam.tf index 436a4398..37d7ed6b 100644 --- a/iam.tf +++ b/iam.tf @@ -331,10 +331,10 @@ resource "aws_iam_role_policy_attachment" "additional_one" { ###################################### resource "aws_iam_role_policy_attachment" "additional_many" { - count = local.create_role && var.attach_policies ? var.number_of_policies : 0 + for_each = { for k, v in toset(var.policies) : k => v if local.create_role && var.attach_policies && var.number_of_policies > 0 } role = aws_iam_role.lambda[0].name - policy_arn = var.policies[count.index] + policy_arn = each.value } ###############################