Skip to content

Commit 4e48784

Browse files
committed
emerg: fix terraform resources
1 parent d6d13a0 commit 4e48784

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

terraform/envs/prod/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,9 @@ resource "random_password" "origin_verify_key" {
5757
}
5858
}
5959

60-
// TEMPORARY LINKRY KV IMPORT
61-
import {
62-
to = aws_cloudfront_key_value_store.linkry_kv
63-
id = "${var.ProjectId}-cloudfront-linkry-kv"
64-
}
65-
6660
resource "aws_cloudfront_key_value_store" "linkry_kv" {
6761
name = "${var.ProjectId}-cloudfront-linkry-kv"
6862
}
69-
//
7063

7164
module "alarms" {
7265
source = "../../modules/alarms"
@@ -80,7 +73,7 @@ module "alarms" {
8073
module "lambdas" {
8174
source = "../../modules/lambdas"
8275
ProjectId = var.ProjectId
83-
RunEnvironment = "dev"
76+
RunEnvironment = "prod"
8477
LinkryKvArn = aws_cloudfront_key_value_store.linkry_kv.arn
8578
OriginVerifyKey = random_password.origin_verify_key.result
8679
LogRetentionDays = 30
@@ -100,6 +93,15 @@ module "frontend" {
10093
LinkryKvArn = aws_cloudfront_key_value_store.linkry_kv.arn
10194
}
10295

96+
resource "aws_lambda_event_source_mapping" "queue_consumer" {
97+
depends_on = [module.lambdas, module.sqs_queues]
98+
for_each = toset([module.sqs_queues.main_queue_arn, module.sqs_queues.sales_email_queue_arn])
99+
batch_size = 5
100+
event_source_arn = each.key
101+
function_name = module.lambdas.core_sqs_consumer_lambda_arn
102+
function_response_types = ["ReportBatchItemFailures"]
103+
}
104+
103105
// This section last: moved records into modules
104106
moved {
105107
from = aws_dynamodb_table.app_audit_log

terraform/envs/qa/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,10 @@ resource "random_password" "origin_verify_key" {
5757
force_recreation = formatdate("DD-MMM-YYYY", plantimestamp())
5858
}
5959
}
60-
61-
// TEMPORARY LINKRY KV IMPORT
62-
import {
63-
to = aws_cloudfront_key_value_store.linkry_kv
64-
id = "${var.ProjectId}-cloudfront-linkry-kv"
65-
}
66-
6760
resource "aws_cloudfront_key_value_store" "linkry_kv" {
6861
name = "${var.ProjectId}-cloudfront-linkry-kv"
6962
}
70-
//
63+
7164

7265
module "lambdas" {
7366
source = "../../modules/lambdas"
@@ -127,6 +120,15 @@ resource "aws_route53_record" "linkry" {
127120
evaluate_target_health = false
128121
}
129122
}
123+
resource "aws_lambda_event_source_mapping" "queue_consumer" {
124+
depends_on = [module.lambdas, module.sqs_queues]
125+
for_each = toset([module.sqs_queues.main_queue_arn, module.sqs_queues.sales_email_queue_arn])
126+
batch_size = 5
127+
event_source_arn = each.key
128+
function_name = module.lambdas.core_sqs_consumer_lambda_arn
129+
function_response_types = ["ReportBatchItemFailures"]
130+
}
131+
130132

131133
// This section last: moved records into modules
132134
moved {

terraform/modules/lambdas/main.tf

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ locals {
1818
entra = aws_iam_policy.entra_policy.arn
1919
}
2020
sqs_policies = {
21-
sqs = aws_iam_policy.sqs_policy.arn
22-
shared = aws_iam_policy.shared_iam_policy.arn
21+
sqs = aws_iam_policy.sqs_policy.arn
22+
shared = aws_iam_policy.shared_iam_policy.arn
23+
managed = "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole"
2324
}
2425
api_policies = {
2526
api = aws_iam_policy.api_only_policy.arn
@@ -45,13 +46,6 @@ resource "aws_iam_role" "api_role" {
4546
Principal = {
4647
Service = "lambda.amazonaws.com"
4748
},
48-
Condition = {
49-
ArnLike = {
50-
"AWS:SourceArn" = [
51-
"arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.core_api_lambda_name}"
52-
]
53-
}
54-
}
5549
},
5650
]
5751
})
@@ -67,13 +61,6 @@ resource "aws_iam_role" "sqs_consumer_role" {
6761
Effect = "Allow"
6862
Principal = {
6963
Service = "lambda.amazonaws.com"
70-
},
71-
Condition = {
72-
ArnLike = {
73-
"AWS:SourceArn" = [
74-
"arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${local.core_sqs_consumer_lambda_name}"
75-
]
76-
}
7764
}
7865
},
7966
]
@@ -386,6 +373,11 @@ output "core_api_lambda_name" {
386373
value = local.core_api_lambda_name
387374
}
388375

376+
output "core_sqs_consumer_lambda_arn" {
377+
value = aws_lambda_function.sqs_lambda.arn
378+
}
379+
380+
389381
output "core_sqs_consumer_lambda_name" {
390382
value = local.core_sqs_consumer_lambda_name
391383
}

terraform/modules/sqs/main.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ resource "aws_sqs_queue" "sales_email_queue" {
3030
})
3131
}
3232

33-
resource "aws_lambda_event_source_mapping" "queue_consumer" {
34-
for_each = toset([aws_sqs_queue.app_queue.arn, aws_sqs_queue.sales_email_queue.arn])
35-
batch_size = 5
36-
event_source_arn = each.key
37-
function_name = var.core_sqs_consumer_lambda_name
38-
function_response_types = ["ReportBatchItemFailures"]
39-
}
40-
4133
output "main_queue_arn" {
4234
description = "Main Queue Arn"
4335
value = aws_sqs_queue.app_queue.arn

0 commit comments

Comments
 (0)