-
Notifications
You must be signed in to change notification settings - Fork 6
/
multiple-lambdas-integration.tf
68 lines (63 loc) · 3.06 KB
/
multiple-lambdas-integration.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module "frontend_lambda_function" {
count = local.multiple_lambda_integration ? 1 : 0
source = "./modules/lambda"
global_tags = var.global_tags
tags = var.tags
environment = var.environment
integration_type = var.integration_type
# Please do not change or replace the 'frontend' suffix since there a logic in the bot based in it
resource_name_pattern = local.api_triggered_function_name
env_vars = local.env_vars
logs_retention_in_days = var.lambda_logs_retention_in_days
should_write_logs = var.lambda_enable_logs
lambda_handler = local.frontend_lambda_handler
timeout = var.lambda_function_timeout
memory_size = var.lambda_function_memory_size
publish = var.lambda_publish
secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : []
lambda_source_code_filename = "frontend.zip"
lambda_source_code_path = var.frontend_lambda_source_code_path
role_arn = module.lambda_role.lambda_role_arn
}
module "backend_lambda_function" {
count = local.multiple_lambda_integration ? 1 : 0
source = "./modules/lambda"
global_tags = var.global_tags
tags = var.tags
environment = var.environment
integration_type = var.integration_type
# Please do not change or replace the 'backend' suffix since there a logic in the bot based in it
resource_name_pattern = "${local.resource_name_pattern}-backend"
env_vars = local.env_vars
logs_retention_in_days = var.lambda_logs_retention_in_days
should_write_logs = var.lambda_enable_logs
lambda_handler = local.backend_lambda_handler
timeout = var.lambda_function_timeout
memory_size = var.lambda_function_memory_size
publish = var.lambda_publish
secrets_arns = var.store_secret_in_secrets_manager ? module.secrets_manager[0].secrets_arns : []
lambda_source_code_filename = "backend.zip"
lambda_source_code_path = var.backend_lambda_source_code_path
role_arn = module.lambda_role.lambda_role_arn
}
data "aws_iam_policy_document" "lambda_invoke_policy_document" {
statement {
sid = ""
effect = "Allow"
actions = ["lambda:InvokeFunction", "lambda:InvokeAsync"]
resources = local.multiple_lambda_integration ? [module.backend_lambda_function[0].lambda_arn] : []
}
}
resource "aws_iam_policy" "lambda_invoke_iam_policy" {
count = local.multiple_lambda_integration ? 1 : 0
policy = data.aws_iam_policy_document.lambda_invoke_policy_document.json
tags = merge(
var.global_tags,
lookup(var.tags, "iam", {}),
)
}
resource "aws_iam_role_policy_attachment" "lambda_invoke_policy_attachment" {
count = local.multiple_lambda_integration ? 1 : 0
role = module.lambda_role.lambda_role_name
policy_arn = aws_iam_policy.lambda_invoke_iam_policy[count.index].arn
}