Skip to content

Commit 4990621

Browse files
committed
fix role attachment
1 parent e3490b5 commit 4990621

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

terraform/modules/lambdas/main.tf

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ data "archive_file" "sqs_lambda_code" {
1313
locals {
1414
core_api_lambda_name = "${var.ProjectId}-main-server"
1515
core_sqs_consumer_lambda_name = "${var.ProjectId}-sqs-consumer"
16+
entra_policies = {
17+
shared = aws_iam_policy.shared_iam_policy.arn
18+
entra = aws_iam_policy.entra_policy.arn
19+
}
20+
sqs_policies = {
21+
sqs = aws_iam_policy.sqs_policy.arn
22+
shared = aws_iam_policy.shared_iam_policy.arn
23+
}
24+
api_policies = {
25+
api = aws_iam_policy.api_only_policy.arn
26+
shared = aws_iam_policy.shared_iam_policy.arn
27+
}
1628
}
1729
data "aws_caller_identity" "current" {}
1830
data "aws_region" "current" {}
@@ -295,20 +307,20 @@ resource "aws_iam_policy" "shared_iam_policy" {
295307
}
296308

297309
resource "aws_iam_role_policy_attachment" "api_attach" {
298-
for_each = toset([aws_iam_policy.shared_iam_policy.arn, aws_iam_policy.api_only_policy.arn])
310+
for_each = local.api_policies
299311
role = aws_iam_role.api_role.name
300-
policy_arn = each.key
312+
policy_arn = each.value
301313
}
302314

303315
resource "aws_iam_role_policy_attachment" "entra_attach" {
304-
for_each = toset([aws_iam_policy.shared_iam_policy.arn, aws_iam_policy.entra_policy.arn])
316+
for_each = local.entra_policies
305317
role = aws_iam_role.entra_role.name
306-
policy_arn = each.key
318+
policy_arn = each.value
307319
}
308320
resource "aws_iam_role_policy_attachment" "sqs_attach_shared" {
309-
for_each = toset(["arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole", aws_iam_policy.sqs_policy.arn, aws_iam_policy.shared_iam_policy.arn])
321+
for_each = local.sqs_policies
310322
role = aws_iam_role.sqs_consumer_role.name
311-
policy_arn = each.key
323+
policy_arn = each.value
312324
}
313325

314326
resource "aws_lambda_function" "api_lambda" {

0 commit comments

Comments
 (0)