Skip to content

Commit

Permalink
Move clamav on ECS (#4190)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno authored Nov 30, 2024
1 parent 5277de4 commit 6d5c60e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 18 deletions.
17 changes: 0 additions & 17 deletions infrastructure/applications/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions infrastructure/applications/applications.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ module "pycon_backend" {
}
}

module "clamav" {
source = "./clamav"
cluster_id = module.cluster.cluster_id
logs_group_name = module.cluster.logs_group_name

providers = {
aws = aws
aws.us = aws.us
}
}

# Other resources

module "database" {
Expand Down
54 changes: 54 additions & 0 deletions infrastructure/applications/clamav/task.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resource "aws_ecs_task_definition" "clamav" {
family = "pythonit-${terraform.workspace}-clamav"

container_definitions = jsonencode([
{
name = "clamav"
image = "clamav/clamav-debian:1.4.1"
memoryReservation = 1000
essential = true

portMappings = [
{
containerPort = 3310
hostPort = 3310
},
]

mountPoints = []

logConfiguration = {
logDriver = "awslogs"
options = {
"awslogs-group" = var.logs_group_name
"awslogs-region" = "eu-central-1"
"awslogs-stream-prefix" = "clamav"
}
}

healthCheck = {
retries = 3
command = [
"CMD-SHELL",
"echo 1"
]
timeout = 3
interval = 10
}

stopTimeout = 300
}
])

requires_compatibilities = []
tags = {}
}

resource "aws_ecs_service" "clamav" {
name = "clamav"
cluster = var.cluster_id
task_definition = aws_ecs_task_definition.clamav.arn
desired_count = 1
deployment_minimum_healthy_percent = 0
deployment_maximum_percent = 100
}
2 changes: 2 additions & 0 deletions infrastructure/applications/clamav/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
variable "cluster_id" {}
variable "logs_group_name" {}
19 changes: 19 additions & 0 deletions infrastructure/applications/cluster/security.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ resource "aws_security_group_rule" "out_redis" {
security_group_id = aws_security_group.server.id
}

resource "aws_security_group_rule" "in_clamav" {
type = "egress"
from_port = 3310
to_port = 3310
protocol = "tcp"
source_security_group_id = aws_security_group.server.id
security_group_id = aws_security_group.server.id
}

resource "aws_security_group_rule" "out_clamav" {
# needed by fargate to connect to the server with clamav
type = "ingress"
from_port = 3310
to_port = 3310
protocol = "tcp"
source_security_group_id = aws_security_group.server.id
security_group_id = aws_security_group.server.id
}

resource "aws_security_group_rule" "web_http" {
type = "ingress"
from_port = 80
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/applications/pycon_backend/worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ locals {
},
{
name = "CLAMAV_HOST",
value = module.secrets.value.clamav_host
value = var.server_ip
},
{
name = "ECS_NETWORK_CONFIG",
Expand Down

0 comments on commit 6d5c60e

Please sign in to comment.