Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fargate/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ inputs:
security_groups:
type: list(string)

outputs: {}
outputs:
http_endpoint:
type: string
description: "HTTP endpoint URL for service-to-service communication"
12 changes: 12 additions & 0 deletions fargate/module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,17 @@ resource "aws_lb_listener_rule" "service" {
}
}

resource "aws_security_group_rule" "service_ingress_from_alb" {
count = length(var.suga.services) > 0 && var.alb_security_group != null ? 1 : 0

type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
security_group_id = var.alb_security_group
self = true
description = "Allow service-to-service communication via ALB for ${var.suga.name}"
}



5 changes: 3 additions & 2 deletions fargate/module/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
output "suga" {
value = {
id = aws_ecs_service.service.id
domain_name = data.aws_lb.alb.dns_name
id = aws_ecs_service.service.id
domain_name = data.aws_lb.alb.dns_name
http_endpoint = "http://${data.aws_lb.alb.dns_name}/${var.suga.name}"
exports = {
resources = {
"aws_lb" = var.alb_arn
Expand Down
6 changes: 6 additions & 0 deletions fargate/module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ variable "suga" {
image_id = string
env = map(string)
identities = map(any)
services = optional(map(object({
actions = list(string)
identities = map(object({
exports = map(string)
}))
})), {})
})
}

Expand Down
5 changes: 4 additions & 1 deletion lambda/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ inputs:
type: list(string)
description: 'Security group IDs controlling network access when Lambda runs in VPC. Must be used with subnet_ids - both provided for VPC deployment or both empty for internet-only Lambda. Configure outbound rules for database, API, or service access (e.g. `["sg-lambda-rds", "sg-lambda-redis"]`)'

outputs: {}
outputs:
http_endpoint:
type: string
description: "HTTP endpoint URL for service-to-service communication"
33 changes: 33 additions & 0 deletions lambda/module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ resource "aws_lambda_function_url" "endpoint" {
# }
}

resource "aws_iam_policy" "service_callers" {
for_each = var.suga.services

name = "${local.lambda_name}-caller-${each.key}"

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "lambda:InvokeFunctionUrl"
Resource = aws_lambda_function_url.endpoint.function_arn
}
]
})
}

resource "aws_iam_role_policy_attachment" "service_callers" {
for_each = var.suga.services

role = each.value.identities["aws:iam:role"].exports["aws_iam_role:name"]
policy_arn = aws_iam_policy.service_callers[each.key].arn
}

resource "aws_lambda_permission" "service_invokers" {
for_each = var.suga.services

statement_id = "AllowInvokeFrom${replace(each.key, "-", "")}"
action = "lambda:InvokeFunctionUrl"
function_name = aws_lambda_function.function.function_name
principal = each.value.identities["aws:iam:role"].exports["aws_iam_role:arn"]
}

# Create role and policy to allow schedule to invoke lambda
resource "aws_iam_role" "role" {
assume_role_policy = jsonencode({
Expand Down
5 changes: 3 additions & 2 deletions lambda/module/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
output "suga" {
value = {
id = aws_lambda_function.function.arn
domain_name = split("/", aws_lambda_function_url.endpoint.function_url)[2]
id = aws_lambda_function.function.arn
domain_name = split("/", aws_lambda_function_url.endpoint.function_url)[2]
http_endpoint = aws_lambda_function_url.endpoint.function_url
exports = {
resources = {
"aws_lambda_function" = aws_lambda_function.function.arn
Expand Down
6 changes: 6 additions & 0 deletions lambda/module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ variable "suga" {
identities = map(object({
exports = map(string)
}))
services = optional(map(object({
actions = list(string)
identities = map(object({
exports = map(string)
}))
})), {})
})
}

Expand Down
Loading