Skip to content

Commit

Permalink
Fix networking configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Apr 18, 2024
1 parent 82606fa commit f10966a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
36 changes: 28 additions & 8 deletions tf/modules/ooniapi_service/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
locals {
name = "ooniapi-service-${var.service_name}"
# We construct a stripped name that is without the "ooni" substring and all
# vocals are stripped.
stripped_name = replace(replace(var.service_name, "ooni", ""), "[aeiou]", "")
# Short prefix should be less than 5 characters
short_prefix = "oo${substr(var.service_name, 0, 3)}"
}

resource "aws_iam_role" "ooniapi_service_task" {
Expand Down Expand Up @@ -65,6 +70,7 @@ resource "aws_ecs_task_definition" "ooniapi_service" {
containerPort = local.container_port,
}
],

environment = [
for k, v in var.task_environment : {
name = k,
Expand Down Expand Up @@ -112,6 +118,10 @@ resource "aws_ecs_service" "ooniapi_service" {
container_port = "80"
}

network_configuration {
subnets = var.subnet_ids
}

depends_on = [
aws_alb_listener.ooniapi_service_http,
]
Expand All @@ -123,20 +133,30 @@ resource "aws_ecs_service" "ooniapi_service" {

# The direct target group is used for the direct domain name mapping
resource "aws_alb_target_group" "ooniapi_service_direct" {
name = "${local.name}-direct"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
name_prefix = "${local.short_prefix}D"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"

lifecycle {
create_before_destroy = true
}

tags = var.tags
}

# The mapped target group is used for mapping it in the main API load balancer
resource "aws_alb_target_group" "ooniapi_service_mapped" {
name = "${local.name}-mapped"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
name_prefix = "${local.short_prefix}M"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"

lifecycle {
create_before_destroy = true
}

tags = var.tags
}
Expand Down
15 changes: 14 additions & 1 deletion tf/modules/oonith_service/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
locals {
name = "oonith-service-${var.service_name}"
# We construct a stripped name that is without the "ooni" substring and all
# vocals are stripped.
stripped_name = replace(replace(var.service_name, "ooni", ""), "[aeiou]", "")
# Short prefix should be less than 5 characters
short_prefix = "oo${substr(var.service_name, 0, 3)}"
}

resource "aws_iam_role" "oonith_service_task" {
Expand Down Expand Up @@ -108,6 +113,10 @@ resource "aws_ecs_service" "oonith_service" {
container_port = "80"
}

network_configuration {
subnets = var.subnet_ids
}

depends_on = [
aws_alb_listener.oonith_service_http,
]
Expand All @@ -119,12 +128,16 @@ resource "aws_ecs_service" "oonith_service" {

# The direct
resource "aws_alb_target_group" "oonith_service_direct" {
name = "${local.name}-direct"
name_prefix = "${local.short_prefix}D"
port = 80
protocol = "HTTP"
vpc_id = var.vpc_id
target_type = "ip"

lifecycle {
create_before_destroy = true
}

tags = var.tags
}

Expand Down

0 comments on commit f10966a

Please sign in to comment.